Java: How to handle a SIGTERM only?

旧时模样 提交于 2019-11-27 06:27:01

问题


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.

details of signals
a slight variation of this qns


回答1:


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


来源:https://stackoverflow.com/questions/5846743/java-how-to-handle-a-sigterm-only

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!