Overview | Package | Class | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.tomcat.util.threads
Class ThreadPool

    java.lang.Object
      org.apache.tomcat.util.threads.ThreadPool

public class ThreadPool
extends java.lang.Object

A thread pool that is trying to copy the apache process management.

Author:
  Gal Shachor

Nested Class Summary
`static class` | `ThreadPool.ControlRunnable` A Thread object that executes various actions ( ThreadPoolRunnable ) under control of ThreadPool
`static class` | `ThreadPool.MonitorRunnable` Periodically execute an action - cleanup in this case
`static interface` | `ThreadPool.ThreadPoolListener` Interface to allow applications to be notified when a threads are created and stopped.

Field Summary
`protected int` | `currentThreadCount`
`protected int` | `currentThreadsBusy`
`protected boolean` | `isDaemon`
`protected java.util.Vector` | `listeners`
`static int` | `MAX_SPARE_THREADS`
`static int` | `MAX_THREADS`
`static int` | `MAX_THREADS_MIN`
`protected int` | `maxSpareThreads`
`protected int` | `maxThreads`
`static int` | `MIN_SPARE_THREADS`
`protected int` | `minSpareThreads`
`protected ThreadPool.MonitorRunnable` | `monitor`
`protected java.lang.String` | `name` Name of the threadpool
`protected ThreadPool.ControlRunnable[]` | `pool`
`protected int` | `sequence` Sequence.
`protected boolean` | `stopThePool`
`protected java.util.Hashtable` | `threads` The threads that are part of the pool.
`static int` | `WORK_WAIT_TIMEOUT`

Constructor Summary
`ThreadPool()` Constructor.

Method Summary
`void` | `addThread(java.lang.Thread t, ThreadPool.ControlRunnable cr)`
`void` | `addThreadPoolListener(ThreadPool.ThreadPoolListener tpl)`
`protected void` | `adjustLimits()`
`protected void` | `checkSpareControllers()` Called by the monitor thread to harvest idle threads.
`static ThreadPool` | `createThreadPool(boolean jmx)` Create a ThreadPool instance.
`int` | `getCurrentThreadCount()`
`int` | `getCurrentThreadsBusy()`
`boolean` | `getDaemon()`
`static int` | `getDebug()`
`int` | `getMaxSpareThreads()`
`int` | `getMaxThreads()`
`int` | `getMinSpareThreads()`
`ThreadPool.MonitorRunnable` | `getMonitor()`
`java.lang.String` | `getName()`
`int` | `getSequence()`
`java.lang.String[]` | `getThreadParam()` Return an array with the current "param" ( XXX better name ?
`java.util.Enumeration` | `getThreads()`
`java.lang.String[]` | `getThreadStatus()` Return an array with the status of each thread.
`boolean` | `isDaemon()`
`protected void` | `notifyThreadEnd(ThreadPool.ControlRunnable c)` Inform the pool that the specific thread finish.
`protected void` | `openThreads(int toOpen)` Create missing threads.
`void` | `removeThread(java.lang.Thread t)`
`protected void` | `returnController(ThreadPool.ControlRunnable c)` Returns the thread to the pool.
`void` | `run(java.lang.Runnable r)`
`void` | `runIt(ThreadPoolRunnable r)` Executes a given Runnable on a thread in the pool, block if needed.
`void` | `setDaemon(boolean b)` The default is true - the created threads will be in daemon mode.
`void` | `setMaxSpareThreads(int maxSpareThreads)`
`void` | `setMaxThreads(int maxThreads)`
`void` | `setMinSpareThreads(int minSpareThreads)`
`void` | `setName(java.lang.String name)`
`void` | `shutdown()` Stop the thread pool
`void` | `start()`
`java.lang.String` | `threadStatusString()` Debug display of the stage of each thread.

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

See Also:
  Constant Field Values

### MAX_THREADS_MIN

    public static final int MAX_THREADS_MIN

See Also:
  Constant Field Values

### MAX_SPARE_THREADS

    public static final int MAX_SPARE_THREADS

See Also:
  Constant Field Values

### MIN_SPARE_THREADS

    public static final int MIN_SPARE_THREADS

See Also:
  Constant Field Values

### WORK_WAIT_TIMEOUT

    public static final int WORK_WAIT_TIMEOUT

See Also:
  Constant Field Values

### pool

    protected ThreadPool.ControlRunnable[] pool

### monitor

    protected ThreadPool.MonitorRunnable monitor

### maxThreads

    protected int maxThreads

### minSpareThreads

    protected int minSpareThreads

### maxSpareThreads

    protected int maxSpareThreads

### currentThreadCount

    protected int currentThreadCount

### currentThreadsBusy

    protected int currentThreadsBusy

### stopThePool

    protected boolean stopThePool

### isDaemon

    protected boolean isDaemon

### threads

    protected java.util.Hashtable threads

  The threads that are part of the pool. Key is Thread, value is the ControlRunnable

### listeners

    protected java.util.Vector listeners

### name

    protected java.lang.String name

  Name of the threadpool

### sequence

    protected int sequence

  Sequence.

Constructor Detail

### ThreadPool

    public ThreadPool()

  Constructor.

Method Detail

### createThreadPool

    public static ThreadPool createThreadPool(boolean jmx)

  Create a ThreadPool instance.

  Parameters:
    `jmx` - True if you want a pool with JMX support. A regular pool will be returned if JMX or the modeler are not available.
  Returns:
    ThreadPool instance. If JMX support is requested, you need to call register() in order to set a name.

### start

    public void start()

### getMonitor

    public ThreadPool.MonitorRunnable getMonitor()

### setMaxThreads

    public void setMaxThreads(int maxThreads)

### getMaxThreads

    public int getMaxThreads()

### setMinSpareThreads

    public void setMinSpareThreads(int minSpareThreads)

### getMinSpareThreads

    public int getMinSpareThreads()

### setMaxSpareThreads

    public void setMaxSpareThreads(int maxSpareThreads)

### getMaxSpareThreads

    public int getMaxSpareThreads()

### getCurrentThreadCount

    public int getCurrentThreadCount()

### getCurrentThreadsBusy

    public int getCurrentThreadsBusy()

### isDaemon

    public boolean isDaemon()

### getDebug

    public static int getDebug()

### setDaemon

    public void setDaemon(boolean b)

  The default is true - the created threads will be in daemon mode. If set to false, the control thread will not be daemon - and will keep the process alive.

### getDaemon

    public boolean getDaemon()

### setName

    public void setName(java.lang.String name)

### getName

    public java.lang.String getName()

### getSequence

    public int getSequence()

### addThread

    public void addThread(java.lang.Thread t,
                          ThreadPool.ControlRunnable cr)

### removeThread

    public void removeThread(java.lang.Thread t)

### addThreadPoolListener

    public void addThreadPoolListener(ThreadPool.ThreadPoolListener tpl)

### getThreads

    public java.util.Enumeration getThreads()

### run

    public void run(java.lang.Runnable r)

### runIt

    public void runIt(ThreadPoolRunnable r)

  Executes a given Runnable on a thread in the pool, block if needed.

### 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(ThreadPool.ControlRunnable c)

  Returns the thread to the pool. Called by threads as they are becoming idel.

### notifyThreadEnd

    protected void notifyThreadEnd(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()

### openThreads

    protected void openThreads(int toOpen)

  Create missing threads.

  Parameters:
    `toOpen` - Total number of threads we'll have open

### threadStatusString

    public java.lang.String threadStatusString()

  Debug display of the stage of each thread. The return is html style, for display in the console ( it can be easily parsed too )

  Returns:

### getThreadStatus

    public java.lang.String[] getThreadStatus()

  Return an array with the status of each thread. The status indicates the current request processing stage ( for tomcat ) or whatever the thread is doing ( if the application using TP provide this info )

  Returns:

### getThreadParam

    public java.lang.String[] getThreadParam()

  Return an array with the current "param" ( XXX better name ? ) of each thread. This is typically the last request.

  Returns:

Overview | Package | Class | Tree | Deprecated | Index | Help

PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2003 Apache Software Foundation. All Rights Reserved.