I'm trying to do some pre-shutdown cleanup when a SIGINT
is sent to my Java application, using the sun.misc.Signal
and sun.misc.SignalHandler
classes.
It appears when I register my handler the default behavior no longer occurs. But there is a SignalHandler.SIG_DFL
field containing "The default signal handler". First of all, is the behavior of the default handler documented anywhere? Secondly, should I prefer the following pattern when implementing my own handlers?
SignalHandler handler = new SignalHandler() {
public void handle(Signal sig) {
... // handle SIGINT
SignalHandler.SIG_DFL.handle(sig);
}
};
Edit: I am aware the sun.misc
package is not portable, and that shutdown hooks are the more robust way to deal with application termination. Suffice to say I am aware of these features, and have a need to handle signals directly. To my knowledge, sun.misc.Signal
is the correct way to do this.