org.apache.avalon.excalibur.thread.impl
Class ResourceLimitingThreadPool

java.lang.Object
  |
  +--java.lang.ThreadGroup
        |
        +--org.apache.avalon.excalibur.thread.impl.ResourceLimitingThreadPool
All Implemented Interfaces:
org.apache.avalon.framework.component.Component, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.logger.LogEnabled, ObjectFactory, ThreadPool

public class ResourceLimitingThreadPool
extends java.lang.ThreadGroup
implements ObjectFactory, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.activity.Disposable, ThreadPool

A Thread Pool which can be configured to have a hard limit on the maximum number of threads which will be allocated. This is very important for servers to avoid running out of system resources. The pool can be configured to block for a new thread or throw an exception. The maximum block time can also be set. Based on org.apache.avalon.excalibur.thread.impl.DefaultThreadPool in the Excalibur sandbox.

Since:
4.1
Version:
CVS $Revision: 1.2 $ $Date: 2002/01/25 01:24:27 $
Author:
Leif Mortenson, Stefano Mazzocchi, Peter Donald

Constructor Summary
ResourceLimitingThreadPool(int max)
          Creates a new ResourceLimitingThreadPool.
ResourceLimitingThreadPool(java.lang.String name, int max)
          Creates a new ResourceLimitingThreadPool with maxStrict enabled, blocking enabled, no block timeout and a trim interval of 10 seconds.
ResourceLimitingThreadPool(java.lang.String name, int max, boolean maxStrict, boolean blocking, long blockTimeout, long trimInterval)
          Creates a new ResourceLimitingThreadPool.
ResourceLimitingThreadPool(java.lang.String name, int max, boolean maxStrict, boolean blocking, long blockTimeout, long trimInterval, ThreadContext context)
          Creates a new ResourceLimitingThreadPool.
 
Method Summary
 void decommission(java.lang.Object object)
          Cleans up any resources associated with the specified object and takes it out of commission.
 void dispose()
          Clean up resources and references.
 void enableLogging(org.apache.avalon.framework.logger.Logger logger)
          Set the logger.
 ThreadControl execute(org.apache.avalon.framework.activity.Executable work)
          Run work in separate thread.
 ThreadControl execute(java.lang.Runnable work)
          Run work in separate thread.
 java.lang.Class getCreatedClass()
          Returns the class of which this ObjectFactory creates instances.
protected  org.apache.avalon.excalibur.thread.impl.WorkerThread getWorker()
          Retrieve a worker thread from pool.
 java.lang.Object newInstance()
          Creates and returns a new WorkerThread.
 
Methods inherited from class java.lang.ThreadGroup
activeCount, activeGroupCount, allowThreadSuspension, checkAccess, destroy, enumerate, enumerate, enumerate, enumerate, getMaxPriority, getName, getParent, interrupt, isDaemon, isDestroyed, list, parentOf, resume, setDaemon, setMaxPriority, stop, suspend, toString, uncaughtException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResourceLimitingThreadPool

public ResourceLimitingThreadPool(int max)
Creates a new ResourceLimitingThreadPool.
Parameters:
max - Maximum number of Poolables which can be stored in the pool, 0 implies no limit.

ResourceLimitingThreadPool

public ResourceLimitingThreadPool(java.lang.String name,
                                  int max)
Creates a new ResourceLimitingThreadPool with maxStrict enabled, blocking enabled, no block timeout and a trim interval of 10 seconds.
Parameters:
name - Name which will used as the thread group name as well as the prefix of the names of all threads created by the pool.
max - Maximum number of WorkerThreads which can be stored in the pool, 0 implies no limit.

ResourceLimitingThreadPool

public ResourceLimitingThreadPool(java.lang.String name,
                                  int max,
                                  boolean maxStrict,
                                  boolean blocking,
                                  long blockTimeout,
                                  long trimInterval)
Creates a new ResourceLimitingThreadPool.
Parameters:
name - Name which will used as the thread group name as well as the prefix of the names of all threads created by the pool.
max - Maximum number of WorkerThreads which can be stored in the pool, 0 implies no limit.
maxStrict - true if the pool should never allow more than max WorkerThreads to be created. Will cause an exception to be thrown if more than max WorkerThreads are requested and blocking is false.
blocking - true if the pool should cause a thread calling get() to block when WorkerThreads are not currently available on the pool.
blockTimeout - The maximum amount of time, in milliseconds, that a call to get() will block before an exception is thrown. A value of 0 implies an indefinate wait.
trimInterval - The minimum interval with which old unused WorkerThreads will be removed from the pool. A value of 0 will cause the pool to never trim WorkerThreads.

ResourceLimitingThreadPool

public ResourceLimitingThreadPool(java.lang.String name,
                                  int max,
                                  boolean maxStrict,
                                  boolean blocking,
                                  long blockTimeout,
                                  long trimInterval,
                                  ThreadContext context)
Creates a new ResourceLimitingThreadPool.
Parameters:
name - Name which will used as the thread group name as well as the prefix of the names of all threads created by the pool.
max - Maximum number of WorkerThreads which can be stored in the pool, 0 implies no limit.
maxStrict - true if the pool should never allow more than max WorkerThreads to be created. Will cause an exception to be thrown if more than max WorkerThreads are requested and blocking is false.
blocking - true if the pool should cause a thread calling get() to block when WorkerThreads are not currently available on the pool.
blockTimeout - The maximum amount of time, in milliseconds, that a call to get() will block before an exception is thrown. A value of 0 implies an indefinate wait.
trimInterval - The minimum interval with which old unused WorkerThreads will be removed from the pool. A value of 0 will cause the pool to never trim WorkerThreads.
context - ThreadContext
Method Detail

newInstance

public java.lang.Object newInstance()
Creates and returns a new WorkerThread.
Specified by:
newInstance in interface ObjectFactory
Returns:
new worker thread

getCreatedClass

public java.lang.Class getCreatedClass()
Returns the class of which this ObjectFactory creates instances.
Specified by:
getCreatedClass in interface ObjectFactory
Returns:
WorkerThread.class

decommission

public void decommission(java.lang.Object object)
Cleans up any resources associated with the specified object and takes it out of commission.
Specified by:
decommission in interface ObjectFactory
Parameters:
object - the object to be decommissioned

enableLogging

public void enableLogging(org.apache.avalon.framework.logger.Logger logger)
Set the logger.
Specified by:
enableLogging in interface org.apache.avalon.framework.logger.LogEnabled
Parameters:
logger -  

dispose

public void dispose()
Clean up resources and references.
Specified by:
dispose in interface org.apache.avalon.framework.activity.Disposable

execute

public ThreadControl execute(java.lang.Runnable work)
Run work in separate thread. Return a valid ThreadControl to control work thread.
Specified by:
execute in interface ThreadPool
Parameters:
work - the work to be executed.
Returns:
the ThreadControl

execute

public ThreadControl execute(org.apache.avalon.framework.activity.Executable work)
Run work in separate thread. Return a valid ThreadControl to control work thread.
Specified by:
execute in interface ThreadPool
Parameters:
work - the work to be executed.
Returns:
the ThreadControl

getWorker

protected org.apache.avalon.excalibur.thread.impl.WorkerThread getWorker()
Retrieve a worker thread from pool.
Returns:
the worker thread retrieved from pool


Copyright © 2001 Apache Jakarta Project. All Rights Reserved.