How can I get IntelliJ debugger to allow my app's shutdown hooks to run?
debugging, intellij-13, intellij-idea, java, shutdown-hook
Solution
Please have a look at the corresponding issue in JetBrains bugtracker.
I've just tested that on Idea 14.0.2 - Stop button is working gracefully so that shutdown hooks are executed.
Unfortunately, you can't use breakpoints in your shutdown hook body when you use Stop button: these breakpoints are silently ignored.
If you need to debug your shutdown hook code (i.e. stop on breakpoints), you could gracefully shutdown your application running in IDEA's debug by calling a command from terminal:
kill -INT <pid>
where `pid` is your application's process ID and could be found, for example by following command:
ps ax | grep java | grep <MainClassNameYouRun>
In this case IDEA will stop on breakpoints in shutdown hook.
Problem
When debugging in IntelliJ an app that registers shutdown hooks, the shutdown hooks do not get called if I click the green "restart" circular arrow button, nor if I click the red square "stop" button. In both cases it appears the app-under-debug is immediately forcibly terminated. (Note this is not a duplicate of How do I stop a processing running in intelliJ such that it calls the shutdown hooks?) When I "manually" send the debugger process an INT signal from the Mac Terminal, of course then my shutdown hooks run as expected. But I haven't been able to discover any configuration settings or controls within the IDE that provoke the desired behavior.