When & how does a JVM Shutdown? What's JVM Shutdown Sequence?
The JVM may shut down either normally or it may also be terminated abnormally:-
- Normal Shutdown - this occurs either when the last non-daemon thread exits OR when Runtime.exit() method (or its equivalent System.exit() method) is invoked. In a normal shutdown the JVM shutdown sequence is invoked. The shutdown sequence of a JVM is consists of two phases - One, execution of all registered shutdown hooks (read more about them in this article - Shutdown Hooks in Java >>) and Two, execution of all uninvoked finalizers (if finalization-on-exit is enabled) and then halting the JVM process.
- Abnormal Shutdown - this occurs when the JVM is terminated using an user interrupt such as typing Ctrl + C or by logging off or shutting down the machine. In such a case, the underlying operating system may allow the JVM to complete its shutdown within a fixed time frame OR it may halt the JVM process immediately and abriptly using the Runtime.halt() method. If the JVM has only a few quick-running shut down hooks (and only a few uninvoked finalizers if the finalization-on-exit is enabled) then an abnormal shut down may also have the same effect in case the OS gives adequate time for the JVM to complete these tasks. Once the shutdown sequence is already in progress and the OS finds that the allowed time has expired then it may call the Runtime.halt() to abruptly terminate the JVM process.
Liked the article? You may like to Subscribe to this blog for regular updates. You may also like to follow the blog to manage the bookmark easily and to tell the world that you enjoy GeekExplains. You can find the 'Followers' widget in the rightmost sidebar.
|
|
|
No comments:
Post a Comment