• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Any way to abort a java app running in a console gracefully?

My program does a lot of processing. It takes a long time.

So if it is running within a windows console (command window) is there some way the user could let my application know that he wants to abort it? Like the ability to press ctrl+c, ctrl+break or something and have the java application recognize this key combo and act upon it to quit gracefully?
0
ycomp
Asked:
ycomp
  • 2
  • 2
1 Solution
 
expertmbCommented:
use addShutdownhook of Runtime.
0
 
sciuriwareCommented:
The accepted answer has nothing to do with the question.

;JOOP!
0
 
ycompAuthor Commented:
I don't know, I was reading about it and I thought that too. But then I noticed that in one of the articles it said that pressing CTRL+C would cause the console to quit and thus trigger the shutdownhook.

If you have any other ideas, let me know. thanks.
0
 
sciuriwareCommented:
You don't need a shutdownhook. The Ctrl/C was the right answer.
What happens next in the application is Ex Libris.

But done is done. Just realise what a shutdownhook is.

;JOOP!
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now