Sometimes it is necessary to perform some
cleanup before
your java application shuts down. But problem is user may not always exit
properly. User may terminate by pressing
Ctrl + C or may simply logoff or
shutdown the Operating system while application is still running.
How to ensure that cleanup code executes in such scenario?
Well! Java provides an elegant way to execute cleanup code in
the middle of shutdown process. We will discuss it in this article.
Let’s start by understanding what happens when JVM (Java
Virtual Machine) shuts down!