1

So, I should handle Ctrl-C. Ok, I can do that by registering a shutdown hook. And it works well until I want to prevent the shutdown. When Ctrl-C pressed I want to ask the user if he really wants to close the app, and if he isn't, then I want my app to continue running. The problem is I don't know how to prevent shutdown after Ctrl-C pressed.

Any help? :)

M--
  • 375
  • 1
  • 2
  • 11

2 Answers2

0

Once you're in a shutdown hook it's too late.

from Runtime.addShutdownHook:

Once the shutdown sequence has begun it can be stopped only by invoking the halt method, which forcibly terminates the virtual machine.

Brad Mace
  • 27,194
  • 17
  • 102
  • 148
0

You can't abort a shutdown from inside a shutdown hook. It will proceed.

user207421
  • 305,947
  • 44
  • 307
  • 483