I need a Monitor Thread monitoring a bunch of Worker Threads. Now what is the best to implement Monitoring?
Option 1> Monitor is constantly iterating a Thread collection to find out who's running... If a Worker completed a task successfully then do something?
Option 2> Monitor is sleeping waiting to be notified by a Worker Thread? If so is there a way to find out which Worker Thread notified?
In your MonitorThread, create a synchronized workerCompleted() method that takes the WorkerThread that is done with its task. The method should add the WT to MT's List of completed WTs. It then wakes up the MT using notify() or interrupt() or some other signal so that it can process the newly completed WT.
You should check out Doug Lea's Concurrent library for some very handy threading classes.
Ravi Sathish
Ranch Hand
Joined: Feb 26, 2002
Posts: 131
posted
0
Dave,
In your MonitorThread, create a synchronized workerCompleted() method that takes the WorkerThread that is done with its task. The method should add the WT to MT's List of completed WTs. It then wakes up the MT using notify() or interrupt() or some other signal so that it can process the newly completed WT.
You should check out Doug Lea's Concurrent library for some very handy threading classes.
I'm still not getting how to implement long running Monitors efficiently.
I have implemented this much so far:
1> workers complete their task and add themselves into a hashtable by invoking Monitor's workerCompleted() method (this is synchronized) ofcourse; after this notifies itself;
2> Now monitor knows its a worker has completed its task; So does some work() goes back to waiting state.
Is this the most efficient implementation..
Viz, Doug Leas util.concurrent package; Channel looks most promising... I need to do read more on how its applicable to currnet scenario..