如何正确使用java.lang.Terminator?
这个类到底是做什么的?
什么是“终止触发的关闭”?
您在程序中的什么地方使用了它,或者什么可能是此类的良好用例?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一次一点地阐述你的观点:
这门课是做什么的?它处理从操作系统接收到的终止信号。
什么是“终止触发的关闭”?由于操作系统向 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.
它是私有包 - 所以你不应该使用它。更好地看看
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.
它为HUP(挂断)注册信号处理程序,INT(中断)和 术语(终止)(参见信号列表)。它通过调用 System.exit() 来关闭应用程序,其值为 sig.getNumber() + 128,即 1+128=129 (HUP)、2+128=130 (INT)、15+128=143 (TERM) )。因此,每当您获得此退出值之一时,您就知道应用程序在从操作系统接收到这些信号之一后已被终结者关闭。请注意,KILL 由操作系统直接处理。
这是一个内部类,因此没有用例。
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.