Adding shutdown hooks

suggest change

Sometimes you need a piece of code to execute when the program stops, such as releasing system resources that you open. You can make a thread run when the program stops with the addShutdownHook method:

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