How can I get IntelliJ debugger to allow my app's shutdown hooks to run?
Asked Answered
O

1

18

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.

Omnibus answered 9/7, 2014 at 17:41 Comment(0)
N
28

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.

Nonrestrictive answered 19/12, 2014 at 1:11 Comment(1)
"Unfortunately, you can't use breakpoints in your shutdown hook body" Thats what I came here for. Thanks.Tribble

© 2022 - 2024 — McMap. All rights reserved.