Adding shutdown hooks

suggest change

Sometimes 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();
}));

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents