Two Laptop Bag
The moose likes Java in General and the fly likes Abnormal Termination Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Abnormal Termination" Watch "Abnormal Termination" New topic

Abnormal Termination

Sumit Mehrotra

Joined: Oct 29, 2003
Posts: 1
Hi All,
I am facing a problem regarding abnormal termination of java program.When some one destroys a java program process from task manager, i need to modify something in the DB.I want to know what method is called when the program is about to exit abnormally.
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Take a look at the API docs for Runtime.addShutdownHook(Thread hook). That may serve your puprose. Pay particular attention to this:

Shutdown hooks should also finish their work quickly. When a program invokes exit the expectation is that the virtual machine will promptly shut down and exit. When the virtual machine is terminated due to user logoff or system shutdown the underlying operating system may only allow a fixed amount of time in which to shut down and exit. It is therefore inadvisable to attempt any user interaction or to perform a long-running computation in a shutdown hook.

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
I agree. Here's the link:
subject: Abnormal Termination
It's not a secret anymore!