Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Handle-a-signal/Java/handle-a-signal-1.java
Normal file
19
Task/Handle-a-signal/Java/handle-a-signal-1.java
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import sun.misc.Signal;
|
||||
import sun.misc.SignalHandler;
|
||||
|
||||
public class ExampleSignalHandler {
|
||||
public static void main(String... args) throws InterruptedException {
|
||||
final long start = System.nanoTime();
|
||||
Signal.handle(new Signal("INT"), new SignalHandler() {
|
||||
public void handle(Signal sig) {
|
||||
System.out.format("\nProgram execution took %f seconds\n", (System.nanoTime() - start) / 1e9f);
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
int counter = 0;
|
||||
while(true) {
|
||||
System.out.println(counter++);
|
||||
Thread.sleep(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Task/Handle-a-signal/Java/handle-a-signal-2.java
Normal file
15
Task/Handle-a-signal/Java/handle-a-signal-2.java
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
public class ExampleSignalHandler {
|
||||
public static void main(String... args) throws InterruptedException {
|
||||
final long start = System.nanoTime();
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
|
||||
public void run() {
|
||||
System.out.format("\nProgram execution took %f seconds\n", (System.nanoTime() - start) / 1e9f);
|
||||
}
|
||||
}));
|
||||
int counter = 0;
|
||||
while(true) {
|
||||
System.out.println(counter++);
|
||||
Thread.sleep(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue