Interview Questions

What is addShutdownHook method in java?

Java Interview Questions and Answers (part 4)


(Continued from previous question...)

57. What is addShutdownHook method in java?

addShutdownHook method in java:

addShutdownHook method registers a new virtual-machine shutdown hook.
A shutdown hook is a initialized but unstarted thread.
When JVM starts its shutdown it will start all registered shutdown hooks in some unspecified order and let them run concurrently.


When JVM (Java virtual machine) shuts down :
When the last non-daemon thread finishes, or
when the System.exit is called.


Once JVM’s shutdown has begun new shutdown hook cannot be registered neither previously-registered hook can be de-registered. Any attempt made to do any of these operations causes an IllegalStateException.

(Continued on next question...)

Other Interview Questions