Is there a way in Java to handle a received SIGTERM?
I am running a java service but do not want to close my java service when the user log off.
Would like to override only the sigterm shutdown handler but retain the handlers for the rest of the signals.
If the Signal
passed to handle
has name "TERM"
then do something, otherwise, ignore it.
class MySignalHandler implements SignalHandler {
public void handle(Signal sig) {
if (!"TERM".equals(sig.getName())) {
SigHandler.SIG_DFL.handle(sig);
return;
}
// Handling code goes here.
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.