org.apache.jcs.utils.threads
Class ThreadPool

java.lang.Object
  extended byorg.apache.jcs.utils.threads.ThreadPool

public class ThreadPool
extends java.lang.Object

A thread pool that is trying to copy the apache process management. asmuts -- Pulled out of tomcat, since it seems to move around and hide. Trying to reduce the number of dependencies


Field Summary
protected  int currentThreadCount
          Description of the Field
protected  int currentThreadsBusy
          Description of the Field
static int MAX_SPARE_THREADS
          Description of the Field
static int MAX_THREADS
          Description of the Field
protected  int maxSpareThreads
          Description of the Field
protected  int maxThreads
          Description of the Field
static int MIN_SPARE_THREADS
          Description of the Field
protected  int minSpareThreads
          Description of the Field
protected  org.apache.jcs.utils.threads.ThreadPool.MonitorRunnable monitor
          Description of the Field
protected  java.util.Vector pool
          Description of the Field
protected  boolean stopThePool
          Description of the Field
static int WORK_WAIT_TIMEOUT
          Description of the Field
 
Constructor Summary
ThreadPool()
          Constructor for the ThreadPool object
 
Method Summary
protected  void adjustLimits()
          Description of the Method
protected  void checkSpareControllers()
          Called by the monitor thread to harvest idle threads.
 int getMaxSpareThreads()
          Gets the maxSpareThreads attribute of the ThreadPool object
 int getMaxThreads()
          Gets the maxThreads attribute of the ThreadPool object
 int getMinSpareThreads()
          Gets the minSpareThreads attribute of the ThreadPool object
static void logFull(org.apache.commons.logging.Log log, int currentThreadCount, int maxThreads)
          Description of the Method
protected  void notifyThreadEnd(org.apache.jcs.utils.threads.ThreadPool.ControlRunnable c)
          Inform the pool that the specific thread finish.
protected  void openThreads(int toOpen)
          Description of the Method
protected  void returnController(org.apache.jcs.utils.threads.ThreadPool.ControlRunnable c)
          Returns the thread to the pool.
 void runIt(IThreadPoolRunnable r)
          Executes a given Runnable on a thread in the pool, block if needed.
 void setMaxSpareThreads(int maxSpareThreads)
          Sets the maxSpareThreads attribute of the ThreadPool object
 void setMaxThreads(int maxThreads)
          Sets the maxThreads attribute of the ThreadPool object
 void setMinSpareThreads(int minSpareThreads)
          Sets the minSpareThreads attribute of the ThreadPool object
 void shutdown()
          Stop the thread pool
 void start()
          Description of the Method
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_THREADS

public static final int MAX_THREADS
Description of the Field

See Also:
Constant Field Values

MAX_SPARE_THREADS

public static final int MAX_SPARE_THREADS
Description of the Field

See Also:
Constant Field Values

MIN_SPARE_THREADS

public static final int MIN_SPARE_THREADS
Description of the Field

See Also:
Constant Field Values

WORK_WAIT_TIMEOUT

public static final int WORK_WAIT_TIMEOUT
Description of the Field

See Also:
Constant Field Values

pool

protected java.util.Vector pool
Description of the Field


monitor

protected org.apache.jcs.utils.threads.ThreadPool.MonitorRunnable monitor
Description of the Field


maxThreads

protected int maxThreads
Description of the Field


minSpareThreads

protected int minSpareThreads
Description of the Field


maxSpareThreads

protected int maxSpareThreads
Description of the Field


currentThreadCount

protected int currentThreadCount
Description of the Field


currentThreadsBusy

protected int currentThreadsBusy
Description of the Field


stopThePool

protected boolean stopThePool
Description of the Field

Constructor Detail

ThreadPool

public ThreadPool()
Constructor for the ThreadPool object

Method Detail

start

public void start()
Description of the Method


setMaxThreads

public void setMaxThreads(int maxThreads)
Sets the maxThreads attribute of the ThreadPool object

Parameters:
maxThreads - The new maxThreads value

getMaxThreads

public int getMaxThreads()
Gets the maxThreads attribute of the ThreadPool object

Returns:
The maxThreads value

setMinSpareThreads

public void setMinSpareThreads(int minSpareThreads)
Sets the minSpareThreads attribute of the ThreadPool object

Parameters:
minSpareThreads - The new minSpareThreads value

getMinSpareThreads

public int getMinSpareThreads()
Gets the minSpareThreads attribute of the ThreadPool object

Returns:
The minSpareThreads value

setMaxSpareThreads

public void setMaxSpareThreads(int maxSpareThreads)
Sets the maxSpareThreads attribute of the ThreadPool object

Parameters:
maxSpareThreads - The new maxSpareThreads value

getMaxSpareThreads

public int getMaxSpareThreads()
Gets the maxSpareThreads attribute of the ThreadPool object

Returns:
The maxSpareThreads value

runIt

public void runIt(IThreadPoolRunnable r)
Executes a given Runnable on a thread in the pool, block if needed.


logFull

public static void logFull(org.apache.commons.logging.Log log,
                           int currentThreadCount,
                           int maxThreads)
Description of the Method


shutdown

public void shutdown()
Stop the thread pool


checkSpareControllers

protected void checkSpareControllers()
Called by the monitor thread to harvest idle threads.


returnController

protected void returnController(org.apache.jcs.utils.threads.ThreadPool.ControlRunnable c)
Returns the thread to the pool. Called by threads as they are becoming idel.


notifyThreadEnd

protected void notifyThreadEnd(org.apache.jcs.utils.threads.ThreadPool.ControlRunnable c)
Inform the pool that the specific thread finish. Called by the ControlRunnable.run() when the runnable throws an exception.


adjustLimits

protected void adjustLimits()
Description of the Method


openThreads

protected void openThreads(int toOpen)
Description of the Method



Copyright © 2002-2005 Apache Software Foundation. All Rights Reserved.