Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 805
Tommy Knowlton Avatar asked Jul 09 '14 17:07

Tommy Knowlton


People also ask

How do I enable debugging in IntelliJ?

Click the Run icon in the gutter, then select Modify Run Configuration. Enter arguments in the Program arguments field. Click the Run button near the main method. From the menu, select Debug.

Why my debugger is not working in IntelliJ?

If the code is outdated, or the versions (the source code and the compiled class) mismatch in any way, it can happen that the debugged is giving the IDE information to show a certain line, but that information is not correct giving the current source code, which might cause what appears to be the debugged "jumping" ...

How do you attach a debugger to a process in IntelliJ?

Press Ctrl+Alt+F5 or choose Run | Attach to Process from the main menu. IntelliJ IDEA will show the list of the running local processes. Select the process to attach to. The processes launched with the debug agent are shown under Java.


1 Answers

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.

like image 137
Daniil Penkin Avatar answered Oct 25 '22 13:10

Daniil Penkin