将信号发送到正在运行的JVM [英] Sending Signals to a Running JVM

查看:345
本文介绍了将信号发送到正在运行的JVM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自定义信号处理程序在自定义java守护程序中捕获TERM,ABRT和INT信号。我在代码中有这个处理程序,以便我可以向它发送TERM信号并通过kill命令正常关闭程序。信号处理程序现在正常工作,但是当我编译代码时,我收到以下警告(多次结束):

I'm using a custom signal handler to catch TERM, ABRT and INT signals in a custom java daemon. I have this handler in the code so that I can send TERM signals to it and gracefully shutdown the program via the kill command. The signal handler works right now, but when I compile the code I'm receiving the following warning (many times over):

警告:sun .misc.SignalHandler是Sun专有的API,在使用这些类时可能会在将来的版本中删除

warning: sun.misc.SignalHandler is Sun proprietary API and may be removed in a future release

import sun.misc.SignalHandler;
import sun.misc.Signal;

有没有更好的方法将信号发送到正在运行的JVM以启动主线程的关闭?我不希望将代码绑定到此API,以便将来删除它。

Is there a better way to send signals to a running JVM to initiate a shutdown of the main thread? I don't like having my code tied to this API when it could be removed in the future.

此代码现在使用1.5.0_22 JVM在Solaris和HPUX上运行。任何帮助或建议将不胜感激。我使用IBM的这个文档来开发信号处理程序:

This code works on Solaris and HPUX today using 1.5.0_22 JVM. Any help or suggestions would be much appreciated. I used this document, from IBM, to develop the signal handler:

http://www.ibm.com/developerworks/java/library/i-signalhandling/

推荐答案

首先,要了解这只是sun.misc包的标准警告。他们告诉您,您使用的API不是标准的Java API。这并不意味着他们将来会积极计划删除此API。 http://java.sun.com/products/jdk/ faq / faq-sun-packages.html

First of all, understand that this is just a standard warning for sun.misc package. They're letting you know that the API you're using is not a standard Java API. It doesn't mean that they're actively planning to remove this API in the future. http://java.sun.com/products/jdk/faq/faq-sun-packages.html

就你的问题而言,我不太清楚为什么java进程处理kill信号的默认方式是对您来说还不够:如何优雅地停止java进程?。如果需要添加其他逻辑,可以添加关闭钩子

As far as your question, it's not quite clear to me why the default way java process handles kill signals is not sufficient for you: How to stop java process gracefully?. If you need to add additional logic, you can add a shutdown hook.

仍然,如果你正在寻找让你的java进程知道它的其他方法退出的时候,你可以让它监听套接字,stdin或命名管道...

Still, If you're looking for other ways to let your java process know it's time to exit, you can have it listen on a socket, or stdin, or a named pipe...

您可能还想查看 JVMTI

这篇关于将信号发送到正在运行的JVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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