How do I stop a process running in IntelliJ such that it calls the shutdown hooks?

JavaIntellij Idea

Java Problem Overview


When I run my program in IntelliJ then use the STOP button, it does not call my shutdown hooks that I've created. Is there a way in IntelliJ to have those called on shutdown?

Java Solutions


Solution 1 - Java

You need to use the Exit button in the Run panel, not the Stop button. Note that it will only work when Running and will not work when Debugging.

Here is the screenshot if you can't find it:

Exit

This feature uses platform specific code and currently works on Windows and Linux only. Once IDEA-56273 is fixed, this feature should be also available on Mac. It is fixed in 10.5 version of IDEA.

Solution 2 - Java

If you are on Mac (and I assume Linux), get the pid and use kill from the terminal. It's an extra step, but works to debug the shutdown handler when you need to.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJamesView Question on Stackoverflow
Solution 1 - JavaCrazyCoderView Answer on Stackoverflow
Solution 2 - JavaEvanView Answer on Stackoverflow