Adding shutdown hooks
suggest changeSometimes you need a piece of code to run when the program stops, such as releasing system resources that you opened. addShutdownHook runs a thread on normal JVM shutdown, not if the process is killed abruptly:
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
ImportantStuff.someImportantIOStream.close();
}));
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents