Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling program termination

 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any finally block to handle thread termination?
 
Haiti Meid
Greenhorn
Posts: 13
Chrome Fedora Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John, you can try this: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Runtime.html#addShutdownHook(java.lang.Thread)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic