Often times I will be building a Java program that will either be run from a command-line or as a system service. In most cases, during development, I’ll be running it directly from the command-line and will want to kill it by pressing control c on the keyboard.
When I do that I want to make sure that my program cleanly exits, closing any open files, socket connections, database connects, or what have you.
To do so, you must invoke → Continue reading “Adding a ShutdownHook to a Java Program to Enable Clean Exit on CTRL-C”