org.knowceans.util
Class DataThreadPool

java.lang.Object
  extended by org.knowceans.util.DataThreadPool
All Implemented Interfaces:
java.io.Serializable

public class DataThreadPool
extends java.lang.Object
implements java.io.Serializable

DataThreadPool is a thread queue that keeps data that can be associated with specific runnables. So only as many data are needed as there are threads, not runnables (tasks) that implement the DataTask interface.
To use this, allocate an array of the data required in the workers, instantiate the pool and add tasks which are executed from an internal queue. Using the notifyCompletion() method allows the caller to wait for completion of all tasks in the queue.

Author:
gregor
See Also:
Serialized Form

Field Summary
 int nThreads
           
 
Constructor Summary
DataThreadPool(int nThreads, java.lang.Object[] data)
          create a thread pool of size nThreads which are assigned data (an array of nThreads objects)
DataThreadPool(int nThreads, java.lang.Object[] data, java.util.Collection<DataTask> queue)
          same as other constructor, with an initial
 
Method Summary
 void add(java.util.Collection<? extends DataTask> tasks)
           
 void add(DataTask task)
           
 void finish()
          complete the current tasks and stop
 int getActive()
           
 boolean isStopping()
          whether this queue is stopping
 void notifyCompletion(java.lang.Object monitor)
          called this before monitor.wait() to wait for completion of all tasks in the pool's queue.
 void start()
          start executing the queue
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nThreads

public int nThreads
Constructor Detail

DataThreadPool

public DataThreadPool(int nThreads,
                      java.lang.Object[] data)
create a thread pool of size nThreads which are assigned data (an array of nThreads objects)

Parameters:
nThreads -
data - may be null

DataThreadPool

public DataThreadPool(int nThreads,
                      java.lang.Object[] data,
                      java.util.Collection<DataTask> queue)
same as other constructor, with an initial

Parameters:
nThreads -
data -
queue -
Method Detail

start

public void start()
start executing the queue


add

public void add(DataTask task)

add

public void add(java.util.Collection<? extends DataTask> tasks)

getActive

public int getActive()

notifyCompletion

public void notifyCompletion(java.lang.Object monitor)
called this before monitor.wait() to wait for completion of all tasks in the pool's queue.


finish

public void finish()
complete the current tasks and stop


isStopping

public boolean isStopping()
whether this queue is stopping

Returns: