Solved

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

Posted on 2004-09-20
5
261 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping2 challenge 13 90
table example 4 29
jdbc error in jsp application 20 44
hibernate jars 4 28
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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 …

776 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