A typical ShutdownHook in Java

Shutdown hooks are a very important feature of the JVM. They provide the capability to do resource cleanup or store application state when the JVM shuts down.

In a typical application there are lot of different type of resources like Database Connection Pool, Thread Pools, Job Schedulers etc. that are instantiated and need to be cleaned up on shutdown. Using the concept of shutdown hook this can be achieved very easily.<!>

The below shows an example of a typical shutdown hook. Depending on your application these resources and its cleanup would be different.