Java | Shutdown Hooks for Java Applications

When java application is stopped, its used services/processes needs to be shutdown gracefully. Java shutdown hooks provides way to gracefully stop the services/processes.

We can write our own logic to do things when shutdown hooks are called. 

Shutdown hooks are called when - 

1. When the main thread exits, the JVM starts its shutdown process

2. Sending an interrupt signal from the OS. Eg. Ctrl + C or OS Shutdown

3. Calling System.exit() from Java code

Shutdown hooks are basically initialized but unstarted threads.

Shutdown hooks are only called on above mentioned conditions, it is not called in case of jvm shut down abruptly eg. power failure etc.



Comments

Popular posts from this blog

Spring | Using TIBCO EMS with Spring framework

TIBCO | For Loop - Accumulate output

TIBCO | JNDI Server & JMS Instance creation