org.objectweb.jonas_ejb.container
Class ThreadPool

java.lang.Object
  extended byorg.objectweb.jonas_ejb.container.ThreadPool

public class ThreadPool
extends java.lang.Object

This is a generic Thread Pool. It manages an ArrayList of Runnable Each thread picks one to run it and loop on the next.

Author:
Philippe Coq, Philippe Durieux

Nested Class Summary
protected  class ThreadPool.ServerThread
          This Thread loops executing runnables added in the pool
 
Field Summary
static int DEFAULT_POOL_MAX_SIZE
           
static int DEFAULT_POOL_MIN_SIZE
           
protected  int freeThreads
           
protected  int maxpoolsz
           
protected  int minpoolsz
           
protected static int poolnumber
           
protected  int poolsz
           
protected  java.util.ArrayList runnablelist
           
protected  boolean valid
           
 
Constructor Summary
ThreadPool()
          Create a pool with default values
ThreadPool(int size)
          Create a pool with a number of threads pre allocated
ThreadPool(int minsz, int maxsz)
          Create a pool with a minimum and a maximum values for thread number.
 
Method Summary
 void addRunnable(java.lang.Runnable runner)
          Add a Runnable in the pool, ready to be run.
 java.lang.Runnable nextRunnable()
           
 void stopThreads()
          Pool is removed: Stop all threads
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_POOL_MIN_SIZE

public static final int DEFAULT_POOL_MIN_SIZE
See Also:
Constant Field Values

DEFAULT_POOL_MAX_SIZE

public static final int DEFAULT_POOL_MAX_SIZE
See Also:
Constant Field Values

poolnumber

protected static int poolnumber

poolsz

protected int poolsz

maxpoolsz

protected int maxpoolsz

minpoolsz

protected int minpoolsz

runnablelist

protected java.util.ArrayList runnablelist

valid

protected boolean valid

freeThreads

protected int freeThreads
Constructor Detail

ThreadPool

public ThreadPool()
Create a pool with default values


ThreadPool

public ThreadPool(int size)
Create a pool with a number of threads pre allocated

Parameters:
size - thread number to start the pool with.

ThreadPool

public ThreadPool(int minsz,
                  int maxsz)
Create a pool with a minimum and a maximum values for thread number.

Parameters:
minsz - thread number to start the pool with.
maxsz - maximum nb of threads in the pool
Method Detail

addRunnable

public void addRunnable(java.lang.Runnable runner)
Add a Runnable in the pool, ready to be run.

Parameters:
runner - The runnable object

nextRunnable

public java.lang.Runnable nextRunnable()
Returns:
the next Runnable to be run.

stopThreads

public void stopThreads()
Pool is removed: Stop all threads