How to set an acknowlegement before JVM shuts down?
How to set an acknowledgement (like email or SMS) before JVM shuts down (this is on the server side, not开发者_运维百科 client)?
You need to add a 'shutdown hook' to the JVM, as described in the Runtime class:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)
If you wanted to print out a message when shutting down, you'd do:
Runtime.getRuntime().addShutdownHook(new Thread() { public void run() {
System.out.println("Goodbye, world!");
} } );
Obviously, fill in the 'goodbye world' bit with what you want.
You may be able to use the Java Shutdown Hook mechanism for this.
It's explained here: http://java.sun.com/j2se/1.5.0/docs/guide/lang/hook-design.html .
I'd recommend writing a Thread and adding it as a runtime hook. You can see examples here.
精彩评论