Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 86
Printing to a specific printer tray (HP 806dn printer) 3 83
Java passing arguments (type error) 2 48
type mismatch (Object[] to double[] 4 8
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

920 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

15 Experts available now in Live!

Get 1:1 Help Now