Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
reverse digits of a number using for loop 5 52
tomcat not starting 6 67
java example issue 3 21
collection output issue 9 36
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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 …

809 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