What does this class exactly do?
What is a "termination-triggered shutdowns"?
Where have you used this in yo开发者_Go百科ur program or what could be a good use case for this class?
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.
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.
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.
精彩评论