thread
Class ThreadPool

java.lang.Object
  extended by thread.ThreadPool

public class ThreadPool
extends java.lang.Object

Thread Pool using stack / list workpile.

Author:
Akitoshi Yoshida, Heinz Kredel.

Field Summary
(package private) static int DEFAULT_SIZE
           
protected  int idleworkers
           
protected  java.util.LinkedList jobstack
           
private static Logger logger
           
protected  StrategyEnumeration strategy
           
protected  PoolThread[] 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

DEFAULT_SIZE

static final int DEFAULT_SIZE
See Also:
Constant Field Values

workers

protected PoolThread[] workers

idleworkers

protected int idleworkers

jobstack

protected java.util.LinkedList jobstack

strategy

protected StrategyEnumeration strategy

logger

private static Logger logger
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.

Returns:
number of worker threads.

getStrategy

public StrategyEnumeration getStrategy()
Get used strategy.

Returns:
strategy.

terminate

public void terminate()
Terminates the threads.


addJob

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

Parameters:
job - Runnable.

getJob

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

Returns:
a Runnable.
Throws:
java.lang.InterruptedException

hasJobs

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

Returns:
true if there are jobs for processing, else false.

hasJobs

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

Parameters:
n - number of jobs to check.
Returns:
true if there are more than n jobs for processing, else false.