org.objectweb.jonas_ejb.container
Class ThreadPool

java.lang.Object
  |
  +--org.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

Inner Class Summary
protected  class ThreadPool.ServerThread
          This Thread loops executing runnables added in the pool
 
Field Summary
protected static int DEFAULT_POOL_MAX_SIZE
           
protected static int DEFAULT_POOL_MIN_SIZE
           
protected  int maxpoolsz
           
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

protected static final int DEFAULT_POOL_MIN_SIZE

DEFAULT_POOL_MAX_SIZE

protected static final int DEFAULT_POOL_MAX_SIZE

poolnumber

protected static int poolnumber

poolsz

protected int poolsz

maxpoolsz

protected int maxpoolsz

runnablelist

protected java.util.ArrayList runnablelist

valid

protected boolean valid
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