de.nava.informa.utils.toolkit
Class WorkersManager

java.lang.Object
  extended by de.nava.informa.utils.toolkit.WorkersManager

public class WorkersManager
extends Object

This class manages worker threads. Its main responsibility is to create / remove worker threads and distribute tasks among them. This is an effort to hide complexity of threading logic from the rest of toolkit. Worker manager receives processing requests from external tools and assigns them to free worker threads. If there's no free worker thread left manager puts item in queue. When worker thread finishes its job it asks for next job using JobSource callback interface. If there is at least one job in queue manager assigns it to worker. If not then worker goes to rest until manager has something to assign.

Worker manager uses instance of WorkerThreadFactoryIF specified on creation to create new worker threads. Client application should use it to create and initialize task-specific workers, which will be started as independent threads.

It's possible to tune number of threads working at a given time using setWorkerThreads(int) method call. Right after the number of threads will change manager will stop unnecessary threads (only after running task completion) or create new worker threads.

Author:
Aleksey Gureev (spyromus@noizeramp.com)

Constructor Summary
WorkersManager(WorkerThreadFactoryIF factory)
          Creates worker manager with default number of worker threads.
WorkersManager(WorkerThreadFactoryIF factory, int workerThreads)
          Creates worker manager.
 
Method Summary
 void process(ChannelRecord record)
          Put the record in processing.
 void setWorkerThreads(int count)
          Changes number of worker threads.
 void terminateAll()
          Terminates all worker threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WorkersManager

public WorkersManager(WorkerThreadFactoryIF factory)
Creates worker manager with default number of worker threads.

Parameters:
factory - worker threads factory.

WorkersManager

public WorkersManager(WorkerThreadFactoryIF factory,
                      int workerThreads)
Creates worker manager.

Parameters:
factory - worker threads factory.
workerThreads - number of worker threads.
Method Detail

setWorkerThreads

public final void setWorkerThreads(int count)
Changes number of worker threads.

Parameters:
count - new number of worker threads.

terminateAll

public final void terminateAll()
Terminates all worker threads.


process

public final void process(ChannelRecord record)
Put the record in processing.

Parameters:
record - record to process.


Copyright © 2002-2007 Niko Schmuck. All Rights Reserved.