This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes Handling program termination Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Handling program termination" Watch "Handling program termination" New topic
Author

Handling program termination

John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Hi,

Is there a way i can handle abrupt termination of my java program in code ( like finally available for the try block)?

My program is a JMS Thread and users can either run it locally on their eclipse or as a Windows Service (not yet implemented).

I would like to handle hard stop like Terminate in Eclipse in code / stop service using Windows -> Services admin tool.
I would like to just print a log.error ("Stopping JMS Service abruptly...."); at the end.

Thanks,
John
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Is there any finally block to handle thread termination?
Haiti Meid
Greenhorn

Joined: Jun 08, 2011
Posts: 13

Hi John, you can try this: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)


Sorry for my English...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Handling program termination