org.apache.excalibur.thread.impl
Class AbstractThreadPool

java.lang.Object
  extended byorg.apache.excalibur.thread.impl.AbstractThreadPool
All Implemented Interfaces:
ThreadPool

public abstract class AbstractThreadPool
extends java.lang.Object
implements 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

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.
 ThreadControl execute(Executable work)
          Execute some executable work in a 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
 

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 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)
Execute some executable work in a thread.

Specified by:
execute in interface 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


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