How do I trap CTRL-C in my Java app? - 0 views
-
"// And finally a Main class which tests the two classes // We let the sample thread run for 10 seconds and then // force a Shutdown with System.exit(0). You may stop the // program early by pressing CTRL-C. public class Main { public static void main(String [] args) { Shutdown shutdown = new Shutdown(); try { Runtime.getRuntime().addShutdownHook(new ShutdownThread(shutdown)); System.out.println("[Main thread] Shutdown hook added"); } catch (Throwable t) { // we get here when the program is run with java // version 1.2.2 or older System.out.println("[Main thread] Could not add Shutdown hook"); } try { Thread.currentThread().sleep(10000); } catch (InterruptedException ie) { } System.exit(0); } }"
1 - 2 of 2
Showing 20▼ items per page