| Real'sHowTo |
|
|
Custom Search
|
| Real'sHowTo |
|
|
Custom Search
|
JDK1.3
public class TrapBreak {
public static void main(String args[]) throws Exception{
new TrapBreak().doit();
}
public void doit() throws Exception{
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
System.out.println("*** END ***");
}
});
while(true) { Thread.sleep(100); System.out.print("."); }
}
}To test it out on Windows, in DOS window, start the class with
C:\temp> java TrapBreak >out.log
Now check the out.log file, you will find "*** END ***" written by our ShutdownHook.
..................*** END ***
Written and compiled by Réal Gagnon ©1998-2013
[ home ]