如何正确使用java.lang.Terminator?

发布于 2024-09-03 22:11:19 字数 118 浏览 7 评论 0原文

  • 这个类到底是做什么的?

  • 什么是“终止触发的关闭”?

  • 您在程序中的什么地方使用了它,或者什么可能是此类的良好用例?

  • What does this class exactly do?

  • What is a "termination-triggered shutdowns"?

  • Where have you used this in your program or what could be a good use case for this class?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

感性 2024-09-10 22:11:19

一次一点地阐述你的观点:

  • 这门课是做什么的?它处理从操作系统接收到的终止信号。

  • 什么是“终止触发的关闭”?由于操作系统向 Java 进程发送信号而导致 JVM 关闭,例如,当您关闭计算机时。

  • 如何使用它?它不适合在您的程序中使用,因为它是包私有的,并且由 JVM 本身用来处理从操作系统接收到的终止信号。

Taking your points one at a time:

  • What does this class do? It handles termination signals received from the Operating System.

  • What are "termination-triggered shutdowns"? A shut down of the JVM caused by the Operating System sending a signal to the Java process, e.g. when you shut down your computer.

  • How can it be used? It's not intended for use in your programs as it is package private and is used by the JVM itself to handle termination signals received from the Operating System.

冷情 2024-09-10 22:11:19

它是私有包 - 所以你不应该使用它。更好地看看
Shutdown Hooks API 的设计如果你想在关机时执行代码。

It's package private - so you're not supposed to use it. Better look at
Design of the Shutdown Hooks API if you want to execute code upon shutdown.

回忆那么伤 2024-09-10 22:11:19

It registers signal handlers for HUP (Hangup), INT (Interrupt) and TERM (Termination) (see List of Signals). It shuts down the application by calling System.exit() with a value of sig.getNumber() + 128, i.e. 1+128=129 (HUP), 2+128=130 (INT), 15+128=143 (TERM). So whenever you get one of this exit values, you know that the application was shut down by Terminator after receiving one of these signals from the OS. Note that KILL is handled by the OS directly.

This is a internal class, hence no usecase.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文