|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.knowceans.util.DataThreadPool
public class DataThreadPool
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.
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 |
---|
public int nThreads
Constructor Detail |
---|
public DataThreadPool(int nThreads, java.lang.Object[] data)
nThreads
- data
- may be nullpublic DataThreadPool(int nThreads, java.lang.Object[] data, java.util.Collection<DataTask> queue)
nThreads
- data
- queue
- Method Detail |
---|
public void start()
public void add(DataTask task)
public void add(java.util.Collection<? extends DataTask> tasks)
public int getActive()
public void notifyCompletion(java.lang.Object monitor)
public void finish()
public boolean isStopping()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |