org.jwarp.service.threadpool
Class ThreadPool

java.lang.Object
  |
  +--java.lang.ThreadGroup
        |
        +--org.jwarp.service.threadpool.ThreadPool
All Implemented Interfaces:
IThreadPool

public class ThreadPool
extends java.lang.ThreadGroup
implements IThreadPool

The ThreadPool manages a pool of threads.
In the thread pool, as its name suggests, some threads are waiting for work to appear in the pool. As soon as there is work one of the waiting threads will take it and work on it.
The pool has an initial amount of threads which are created when the pool is created. It has also a maximum limit to which he can extend the number of threads. When work is added and no thread is currently waiting, the pool creates a new thread unless the maximum count of threads is already reached.
Currently the pool does not destroy any thread he once created.

Author:
Anatole Tresch

Fields inherited from class java.lang.ThreadGroup
daemon, destroyed, groups, maxPriority, name, ngroups, nthreads, parent, threads, vmAllowSuspension
 
Constructor Summary
ThreadPool(org.jdom.Element config)
          Creates a thread pool.
ThreadPool(int initPoolSize, int maxPoolSize)
          Creates a thread pool.
ThreadPool(java.lang.String threadPoolName, int initPoolSize, int maxPoolSize)
          Creates a thread pool.
 
Method Summary
 void cancel(java.lang.Runnable work)
          Try to stop a thread.
 void execute(java.lang.Runnable work)
          Add work which will be eventually done by one of the threads in this pool.
protected  void finalize()
           
 int getCurrentPoolSize()
          Gets the number of threads in this pool.
 void resumePool()
          resume a pool.
 void startPool()
          Stop a pool.
 void stopPool()
          Stop a pool.
 void suspendPool()
          Suspend a pool.
 
Methods inherited from class java.lang.ThreadGroup
activeCount, activeGroupCount, add, allowThreadSuspension, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, list, parentOf, remove, resume, setDaemon, setMaxPriority, stop, suspend, toString, uncaughtException
 
Methods inherited from class java.lang.Object
, clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ThreadPool

public ThreadPool(org.jdom.Element config)
Creates a thread pool.
Parameters:
threadPoolName - the name of the thread pool
initPoolSize - the initial size of the thread pool
maxPoolSize - the maximum size of the thread pool
threadFactory - the factory to create the threads

ThreadPool

public ThreadPool(java.lang.String threadPoolName,
                  int initPoolSize,
                  int maxPoolSize)
Creates a thread pool.
Parameters:
threadPoolName - the name of the thread pool
initPoolSize - the initial size of the thread pool
maxPoolSize - the maximum size of the thread pool
threadFactory - the factory to create the threads

ThreadPool

public ThreadPool(int initPoolSize,
                  int maxPoolSize)
Creates a thread pool.
Parameters:
initPoolSize - the initial size of the thread pool
maxPoolSize - the maximum size of the thread pool
threadFactory - the factory to create the threads
Method Detail

execute

public void execute(java.lang.Runnable work)
             throws ThreadPoolStoppedException
Add work which will be eventually done by one of the threads in this pool. The work is executed in a FIFO manner.
Specified by:
execute in interface IThreadPool
Parameters:
work - the work to do

cancel

public void cancel(java.lang.Runnable work)
Try to stop a thread.
Specified by:
cancel in interface IThreadPool
Parameters:
work - the work to do

getCurrentPoolSize

public int getCurrentPoolSize()
Gets the number of threads in this pool.
Specified by:
getCurrentPoolSize in interface IThreadPool
Returns:
the number of threads

stopPool

public void stopPool()
Stop a pool.
Specified by:
stopPool in interface IThreadPool

startPool

public void startPool()
Stop a pool.
Specified by:
startPool in interface IThreadPool

suspendPool

public void suspendPool()
Suspend a pool.
Specified by:
suspendPool in interface IThreadPool

resumePool

public void resumePool()
resume a pool.
Specified by:
resumePool in interface IThreadPool

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object

©   O R C A   S y s t e m s