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

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

问题描述

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

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

至少 SIGINTSIGKILL 应该完全独立于平台.

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天全站免登陆