What is the best way to capture a kill signal in java without using JNI. I did discover the sun.misc.Signal and the sun.misc.SignalHandler and the warning of the possibility of being removed in the future releases.
Would using JNI to call a c lib be the only option i have?
The way to handle this would be to register a shutdown hook. If you use (SIGINT)
kill -2will cause the program to gracefully exit and run the shutdown hooks.I tried the following test program on OSX 10.6.3 and on
kill -9it did NOT run the shutdown hook, didn’t think it would. On akill -15it DOES run the shutdown hook every time.This is the documented way to write your own signal handlers that aren’t shutdown hooks in Java. Be warned that the
com.sun.miscpackages and are un-supported and may be changed or go away at any time and probably only exist in the Sun JVM.