Java:如何只处理SIGTERM? [英] Java: How to handle a SIGTERM only?

查看:643
本文介绍了Java:如何只处理SIGTERM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java中是否有办法处理收到的SIGTERM?

Is there a way in Java to handle a received SIGTERM?

我正在运行一个java服务,但是当用户注销时不想关闭我的java服务。

I am running a java service but do not want to close my java service when the user log off.

想要仅覆盖sigterm关闭处理程序,但保留其余信号的处理程序。

Would like to override only the sigterm shutdown handler but retain the handlers for the rest of the signals.

的细节信号

此qns的略微变化

推荐答案

如果 Signal 传递给句柄名称TERM然后做一些事情,否则,忽略它。

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

这篇关于Java:如何只处理SIGTERM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆