16 lines
539 B
Java
16 lines
539 B
Java
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);
|
|
}
|
|
}
|
|
}
|