处理Java虚拟机中的信号 [英] Handle signals in the Java Virtual Machine

查看:92
本文介绍了处理Java虚拟机中的信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Java虚拟机中处理POSIX信号?

Is it possible to handle POSIX signals within the Java Virtual Machine?

至少 SIGINT

At least SIGINT and SIGKILL should be quite platform independent.

推荐答案

JVM自行响应信号.有些会导致JVM正常关闭,其中包括运行关闭钩子.其他信号将导致JVM在不运行关闭钩子的情况下中止.

The JVM responds to signals on its own. Some will cause the JVM to shutdown gracefully, which includes running shutdown hooks. Other signals will cause the JVM to abort without running shutdown hooks.

关闭挂钩是使用 Runtime.addShutdownHook(Thread).

我不认为JDK提供了一种处理Java应用程序中信号的正式方法.但是,我确实找到了这篇IBM文章,其中介绍了一些未记录的sun.misc.Signal类可以做到这一点.本文始于2002年,并使用JDK 1.3.1,但我已经确认sun.misc.Signal类在JDK 1.6.0中仍然存在.

I don't think the JDK provides an official way to handle signals within your Java application. However, I did find this IBM article, which describes using some undocumented sun.misc.Signal class to do exactly that. The article dates from 2002 and uses JDK 1.3.1, but I've confirmed that the sun.misc.Signal class still exists in JDK 1.6.0.

这篇关于处理Java虚拟机中的信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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