开发者

Java: How to handle a SIGTERM only?

开发者 https://www.devze.com 2023-03-02 02:03 出处:网络
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.

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.

detai开发者_如何学Pythonls of signals

a slight variation of this qns


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.
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消