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

2

81

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?

Possibility answered 18/1, 2011 at 18:16 Comment(0)
M
112

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.

Massenet answered 18/1, 2011 at 18:34 Comment(11)
hrm, I'm totally missing where the "Exit" button is, do you happen to have a screenshot handy? thanks so muchPossibility
Updated my reply with a screenshot.Massenet
that's really weird, here's my runtime panel dropmocks.com/mPyzF I don't see that icon. i'm using intellij 10Possibility
Taking thread dumps and performing graceful shutdown depends on the native component which is currently not available for Mac platform. Updated my reply.Massenet
Do you know why this isn't available from the Debugger?Heartburning
Running on windows with Intellij 13.1.3 and also don't have this button.Shorthand
@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.Leslileslie
Was the "Exit" button removed for OSX? Currently using 15.0.4 and I don't have access to this.Pronation
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.Nonpros
I've been using Intellij for years and this is the first time I've used that "exit" icon - to test shutdown hooks.Conni
Thanks a lot. It still works for Idea 2022.2.1 on WindowsDutybound
S
4

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.

Streaky answered 6/7, 2018 at 18:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.