• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to Monitor Threads?

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ranchers,

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?

Could please suggest better design solutions?

TIA
Ravi
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..

I would appreciate future suggestions

Ravi
 
reply
    Bookmark Topic Watch Topic
  • New Topic