jQuery in Action, 3rd edition
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Handling program termination" Watch "Handling program termination" New topic

Handling program termination

John Jai

Joined: May 31, 2011
Posts: 1776

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.

John Jai

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

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
It's not a secret anymore!