Solved

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

Posted on 2004-09-20
5
259 Views
Last Modified: 2010-03-31
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
Comment
Question by:ycomp
  • 2
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
expertmb earned 500 total points
ID: 12109067
use addShutdownhook of Runtime.
0
 
LVL 6

Expert Comment

by:expertmb
ID: 12109074
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12110410
The accepted answer has nothing to do with the question.

;JOOP!
0
 

Author Comment

by:ycomp
ID: 12113720
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 12119810
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now