edu.jas.util
Class ThreadPool

java.lang.Object
  extended by edu.jas.util.ThreadPool

public class ThreadPool
extends java.lang.Object

Thread pool using stack / list workpile.

Author:
Akitoshi Yoshida, Heinz Kredel

Field Summary
protected  int idleworkers
          Number of idle workers.
protected  java.util.LinkedList<java.lang.Runnable> jobstack
          Work queue / stack.
protected  StrategyEnumeration strategy
           
protected  edu.jas.util.PoolThread[] workers
          Array of workers.
 
Constructor Summary
ThreadPool()
          Constructs a new ThreadPool with strategy StrategyEnumeration.FIFO and size DEFAULT_SIZE.
ThreadPool(int size)
          Constructs a new ThreadPool with strategy StrategyEnumeration.FIFO.
ThreadPool(StrategyEnumeration strategy)
          Constructs a new ThreadPool with size DEFAULT_SIZE.
ThreadPool(StrategyEnumeration strategy, int size)
          Constructs a new ThreadPool.
 
Method Summary
 void addJob(java.lang.Runnable job)
          adds a job to the workpile.
protected  java.lang.Runnable getJob()
          get a job for processing.
 int getNumber()
          number of worker threads.
 StrategyEnumeration getStrategy()
          get used strategy.
 boolean hasJobs()
          check if there are jobs for processing.
 boolean hasJobs(int n)
          check if there are more than n jobs for processing.
 void terminate()
          Terminates the threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

workers

protected edu.jas.util.PoolThread[] workers
Array of workers.


idleworkers

protected int idleworkers
Number of idle workers.


jobstack

protected java.util.LinkedList<java.lang.Runnable> jobstack
Work queue / stack.


strategy

protected StrategyEnumeration strategy
Constructor Detail

ThreadPool

public ThreadPool()
Constructs a new ThreadPool with strategy StrategyEnumeration.FIFO and size DEFAULT_SIZE.


ThreadPool

public ThreadPool(StrategyEnumeration strategy)
Constructs a new ThreadPool with size DEFAULT_SIZE.

Parameters:
strategy - for job processing.

ThreadPool

public ThreadPool(int size)
Constructs a new ThreadPool with strategy StrategyEnumeration.FIFO.

Parameters:
size - of the pool.

ThreadPool

public ThreadPool(StrategyEnumeration strategy,
                  int size)
Constructs a new ThreadPool.

Parameters:
strategy - for job processing.
size - of the pool.
Method Detail

getNumber

public int getNumber()
number of worker threads.


getStrategy

public StrategyEnumeration getStrategy()
get used strategy.


terminate

public void terminate()
Terminates the threads.


addJob

public void addJob(java.lang.Runnable job)
adds a job to the workpile.

Parameters:
job -

getJob

protected java.lang.Runnable getJob()
                             throws java.lang.InterruptedException
get a job for processing.

Throws:
java.lang.InterruptedException

hasJobs

public boolean hasJobs()
check if there are jobs for processing.


hasJobs

public boolean hasJobs(int n)
check if there are more than n jobs for processing.

Parameters:
n - Integer
Returns:
true, if there are possibly more than n jobs.