80

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?

Pang
  • 9,564
  • 146
  • 81
  • 122
James
  • 15,085
  • 25
  • 83
  • 120

2 Answers2

110

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 button

Old versions:

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.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 5
    hrm, I'm totally missing where the "Exit" button is, do you happen to have a screenshot handy? thanks so much – James Jan 18 '11 at 18:42
  • 3
    Updated my reply with a screenshot. – CrazyCoder Jan 18 '11 at 19:08
  • 1
    that's really weird, here's my runtime panel http://www.dropmocks.com/mPyzF I don't see that icon. i'm using intellij 10 – James Jan 18 '11 at 19:28
  • 2
    Taking thread dumps and performing graceful shutdown depends on the native component which is currently not available for Mac platform. Updated my reply. – CrazyCoder Jan 18 '11 at 20:35
  • 33
    Do you know why this isn't available from the Debugger? – Tom McIntyre May 16 '13 at 10:51
  • 3
    Running on windows with Intellij 13.1.3 and also don't have this button. – Roee Gavirel Sep 21 '14 at 07:33
  • @CrazyCoder, would be really great to know, Tom already asked, why this isn't available for Debug Sessions or when this will be available for Debug sessions. – philnate Oct 15 '14 at 19:52
  • 1
    Was the "Exit" button removed for OSX? Currently using 15.0.4 and I don't have access to this. – piofusco Mar 04 '16 at 18:17
  • I have the Exit button on OS X running 2016.1 EAP, and when I click it it does appear to call the shutdown hooks, but it appears to leave the java process behind, which I discovered because it does not release the debug port it was listening on and as such I am unable to start a new instance of my application. I had to kill the java process with Activity Monitor. – JakeRobb Apr 07 '16 at 22:42
  • I've been using Intellij for years and this is the first time I've used that "exit" icon - to test shutdown hooks. – Drakes Mar 01 '19 at 00:19
  • Thanks a lot. It still works for Idea 2022.2.1 on Windows – Vitalii Sep 09 '22 at 14:13
3

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.

Evan
  • 2,441
  • 23
  • 36