Detecting whether a certain thread is running or not.
1 posts in topic
Flat View  Flat View

Posted By:   Val_Blant
Posted On:   Wednesday, March 13, 2002 04:58 PM

Hi. I have a java program that starts a thread. After the thread is started, the program exits.

I need to be able to do 2 things:

  1. Prevent a second thread from being started, if one thread is already running

  2. Stop the thread by running the program that started it again with a different parameter

My problem is that I don't know how to figure out if my thread is already running and how to send a message to it, because the program that had a reference to it was terminated and then started again.

I would appreciate any advise. Thank you.

Re: Detecting whether a certain thread is running or not.

Posted By:   Eric_Lindauer  
Posted On:   Wednesday, March 20, 2002 07:43 AM

Do you mean that you start a *process*? When the first JVM exits, any threads created by it will be destroyed, so any programs that follow this event can safely assume that the first thread is no longer running.

As for inter-JVM communication about the existence of a particular thread ( or process ), there are many ways to do it. You basically need some kind of shared resource which any JVM can read from and modify. When the first thread is started, modify this shared resource to indicate this fact. Other JVMs that are started then check this resource's state before performing any action.

In a robust system, this shared resource would be a database, a JMS topic, etc, but you could do it quickly with a File in a well-known location.

Hope this helps.

About | Sitemap | Contact