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

java.lang.Object
  extended byjava.lang.ThreadGroup
      extended byorg.apache.avalon.excalibur.thread.impl.InstrumentedResourceLimitingThreadPool
All Implemented Interfaces:
Disposable, Instrumentable, LogEnabled, ObjectFactory, ThreadPool

public class InstrumentedResourceLimitingThreadPool
extends java.lang.ThreadGroup
implements ObjectFactory, LogEnabled, Disposable, ThreadPool, Instrumentable

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.

Since:
4.1
Version:
CVS $Revision: 1.1 $ $Date: 2004/03/29 17:22:49 $
Author:
Avalon Development Team

Field Summary
 
Fields inherited from interface org.apache.excalibur.instrument.Instrumentable
EMPTY_INSTRUMENT_ARRAY, EMPTY_INSTRUMENTABLE_ARRAY
 
Constructor Summary
InstrumentedResourceLimitingThreadPool(int max)
          Creates a new ResourceLimitingThreadPool.
InstrumentedResourceLimitingThreadPool(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.
InstrumentedResourceLimitingThreadPool(java.lang.String name, int max, boolean maxStrict, boolean blocking, long blockTimeout, long trimInterval)
          Creates a new ResourceLimitingThreadPool.
 
Method Summary
 void decommission(java.lang.Object object)
           
 void dispose()
          The dispose operation is called at the end of a components lifecycle.
 void enableLogging(Logger logger)
          Provide component with a logger.
 ThreadControl execute(Executable work)
          Run work in separate thread.
 ThreadControl execute(Executable work)
          Run work in separate thread.
 ThreadControl execute(java.lang.Runnable work)
          Run work in separate thread.
 Instrumentable[] getChildInstrumentables()
          Any Object which implements Instrumentable can also make use of other Instrumentable child objects.
 java.lang.Class getCreatedClass()
           
 java.lang.String getInstrumentableName()
          Gets the name of the Instrumentable.
 Instrument[] getInstruments()
          Obtain a reference to all the Instruments that the Instrumentable object wishes to expose.
 int getSize()
          Return the number of worker threads in the pool.
 java.lang.Object newInstance()
           
 void setInstrumentableName(java.lang.String name)
          Sets the name for the Instrumentable.
 
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

InstrumentedResourceLimitingThreadPool

public InstrumentedResourceLimitingThreadPool(int max)
Creates a new ResourceLimitingThreadPool.

Parameters:
max - Maximum number of Poolables which can be stored in the pool, 0 implies no limit.

InstrumentedResourceLimitingThreadPool

public InstrumentedResourceLimitingThreadPool(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.

InstrumentedResourceLimitingThreadPool

public InstrumentedResourceLimitingThreadPool(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.
Method Detail

setInstrumentableName

public void setInstrumentableName(java.lang.String name)
Sets the name for the Instrumentable. The Instrumentable Name is used to uniquely identify the Instrumentable during the configuration of the InstrumentManager and to gain access to an InstrumentableDescriptor through the InstrumentManager. The value should be a string which does not contain spaces or periods.

This value may be set by a parent Instrumentable, or by the InstrumentManager using the value of the 'instrumentable' attribute in the configuration of the component.

Specified by:
setInstrumentableName in interface Instrumentable
Parameters:
name - The name used to identify a Instrumentable.

getInstrumentableName

public java.lang.String getInstrumentableName()
Gets the name of the Instrumentable.

Specified by:
getInstrumentableName in interface Instrumentable
Returns:
The name used to identify a Instrumentable.

getInstruments

public Instrument[] getInstruments()
Obtain a reference to all the Instruments that the Instrumentable object wishes to expose. All sampling is done directly through the Instruments as opposed to the Instrumentable interface.

Specified by:
getInstruments in interface Instrumentable
Returns:
An array of the Instruments available for profiling. Should never be null. If there are no Instruments, then EMPTY_INSTRUMENT_ARRAY can be returned. This should never be the case though unless there are child Instrumentables with Instruments.

getChildInstrumentables

public Instrumentable[] getChildInstrumentables()
Any Object which implements Instrumentable can also make use of other Instrumentable child objects. This method is used to tell the InstrumentManager about them.

Specified by:
getChildInstrumentables in interface Instrumentable
Returns:
An array of child Instrumentables. This method should never return null. If there are no child Instrumentables, then EMPTY_INSTRUMENTABLE_ARRAY can be returned.

getSize

public int getSize()
Return the number of worker threads in the pool.

Returns:
the numebr of worker threads in the pool.

enableLogging

public void enableLogging(Logger logger)
Description copied from interface: LogEnabled
Provide component with a logger.

Specified by:
enableLogging in interface LogEnabled
Parameters:
logger - the logger. Must not be null.

dispose

public void dispose()
Description copied from interface: Disposable
The dispose operation is called at the end of a components lifecycle. This method will be called after Startable.stop() method (if implemented by component). Components use this method to release and destroy any resources that the Component owns.

Specified by:
dispose in interface Disposable

newInstance

public java.lang.Object newInstance()
Specified by:
newInstance in interface ObjectFactory

decommission

public void decommission(java.lang.Object object)
Specified by:
decommission in interface ObjectFactory

getCreatedClass

public java.lang.Class getCreatedClass()
Specified by:
getCreatedClass in interface ObjectFactory

execute

public ThreadControl execute(Executable work)
Run work in separate thread. Return a valid ThreadControl to control work thread.

Parameters:
work - the work to be executed.
Returns:
the ThreadControl

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(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


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.