org.apache.excalibur.thread.impl
Class AbstractThreadPool

java.lang.Object
  extended by org.apache.excalibur.thread.impl.AbstractThreadPool
All Implemented Interfaces:
org.apache.excalibur.thread.ThreadPool
Direct Known Subclasses:
BasicThreadPool

public abstract class AbstractThreadPool
extends java.lang.Object
implements org.apache.excalibur.thread.ThreadPool

This is the base class of all ThreadPools. Sub-classes should implement the abstract methods to retrieve and return Threads to the pool.

Author:
Avalon Development Team

Field Summary
private  int m_level
          A Running number that indicates the number of threads created by pool.
private  java.lang.String m_name
          The name of the thread pool.
private  java.lang.ThreadGroup m_threadGroup
          The thread group associated with pool.
 
Constructor Summary
AbstractThreadPool(java.lang.String name, java.lang.ThreadGroup threadGroup)
          Create a ThreadPool with the specified name.
 
Method Summary
protected  WorkerThread createWorker()
          Create a WorkerThread and start it up.
protected  void destroyWorker(WorkerThread thread)
          Destroy a worker thread by scheduling it for shutdown.
 org.apache.excalibur.thread.ThreadControl execute(org.apache.excalibur.thread.Executable work)
          Execute some executable work in a thread.
 org.apache.excalibur.thread.ThreadControl execute(java.lang.Runnable work)
          Run work in separate thread.
protected  java.lang.String getName()
          Get the name used for thread pool.
protected  java.lang.ThreadGroup getThreadGroup()
          Return the thread group that thread pool is associated with.
protected abstract  WorkerThread getWorker()
          Retrieve a worker thread from pool.
protected  WorkerThread newWorkerThread(java.lang.String name)
          Create a new worker for pool.
protected abstract  void releaseWorker(WorkerThread worker)
          Return the WorkerThread to the pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_threadGroup

private final java.lang.ThreadGroup m_threadGroup
The thread group associated with pool.


m_name

private final java.lang.String m_name
The name of the thread pool. Used in naming threads.


m_level

private int m_level
A Running number that indicates the number of threads created by pool. Starts at 0 and increases.

Constructor Detail

AbstractThreadPool

public AbstractThreadPool(java.lang.String name,
                          java.lang.ThreadGroup threadGroup)
                   throws java.lang.Exception
Create a ThreadPool with the specified name.

Parameters:
name - the name of thread pool (appears in thread group and thread names)
Throws:
java.lang.Exception - if unable to create pool
Method Detail

destroyWorker

protected void destroyWorker(WorkerThread thread)
Destroy a worker thread by scheduling it for shutdown.

Parameters:
thread - the worker thread

createWorker

protected WorkerThread createWorker()
Create a WorkerThread and start it up.

Returns:
the worker thread.

newWorkerThread

protected WorkerThread newWorkerThread(java.lang.String name)
Create a new worker for pool.

Parameters:
name - the name of worker
Returns:
the new WorkerThread

execute

public org.apache.excalibur.thread.ThreadControl execute(java.lang.Runnable work)
Run work in separate thread. Return a valid ThreadControl to control work thread.

Specified by:
execute in interface org.apache.excalibur.thread.ThreadPool
Parameters:
work - the work to be executed.
Returns:
the ThreadControl

execute

public org.apache.excalibur.thread.ThreadControl execute(org.apache.excalibur.thread.Executable work)
Execute some executable work in a thread.

Specified by:
execute in interface org.apache.excalibur.thread.ThreadPool
Parameters:
work - the work
Returns:
the ThreadControl

getName

protected java.lang.String getName()
Get the name used for thread pool. (Used in naming threads).

Returns:
the thread pool name

getThreadGroup

protected java.lang.ThreadGroup getThreadGroup()
Return the thread group that thread pool is associated with.

Returns:
the thread group that thread pool is associated with.

getWorker

protected abstract WorkerThread getWorker()
Retrieve a worker thread from pool.

Returns:
the worker thread retrieved from pool

releaseWorker

protected abstract void releaseWorker(WorkerThread worker)
Return the WorkerThread to the pool.

Parameters:
worker - the worker thread to put back in pool