File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring forum!
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:

Sorry for my English...
I agree. Here's the link:
subject: Handling program termination
It's not a secret anymore!