File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Graceful clean up of daemon process Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Graceful clean up of daemon process" Watch "Graceful clean up of daemon process" New topic

Graceful clean up of daemon process

Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
If my daemon process does not have a remote hook, such as RMI/JMX, that can signal it to shut down gracefully, what is the next best way to do some clean up before the JVM terminates?

This process have several daemon threads that may still be working. If there's some clean up hook that can be registered to the JVM, is there a limit on how long can the clean up code runs before the OS kills the process?

The process is likely to be terminated by "ctrl-c" or linux "kill" command.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2398
Look at the method addShutdownHook in java.lang.Runtime.
I agree. Here's the link:
subject: Graceful clean up of daemon process
It's not a secret anymore!