Stopping threads running a java program
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Naveen_Jacob
Posted On:   Monday, July 15, 2002 11:32 AM

I have a java process which has two threads executing two different programs running on solaris. When I kill the process I get core dump how can I avoid this and stop the process through a shell script.

Re: Stopping threads running a java program

Posted By:   Channing_Walton  
Posted On:   Monday, July 15, 2002 12:51 PM

Hi,
I think you need to use a shutdown hook in the vm to tell your running threads to stop. A shutdown hook is just a means to enable graceful exit.


You add the shutdown hook thus:
 
Runtime.getRuntime().addShutdownHook(shutdownHook);

where shutdownHook is a thread.


The VM only exits when all the shutdown hooks have been run. But, depending on how the VM was terminated, the shutdown hooks may not have a chance to run at all. I think using something like 'kill -9 pid' will kill a VM without hooks running, but CTRL-c for example will allow the hooks to run.


channing

About | Sitemap | Contact