org.apache.tomcat.util.threads
public class ThreadPool extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
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.
|
Modifier and Type | Field and Description |
---|---|
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 int |
threadPriority
Thread priority.
|
protected java.util.Hashtable |
threads
The threads that are part of the pool.
|
static int |
WORK_WAIT_TIMEOUT |
Constructor and Description |
---|
ThreadPool()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
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 ?
|
int |
getThreadPriority()
Returns the priority level of current and
future threads in this pool.
|
java.util.Enumeration |
getThreads() |
java.lang.String[] |
getThreadStatus()
Return an array with the status of each thread.
|
int |
incSequence() |
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 |
setThreadPriority(int threadPriority)
Sets the thread priority for current
and future threads in this pool.
|
void |
shutdown()
Stop the thread pool
|
void |
start() |
java.lang.String |
threadStatusString()
Debug display of the stage of each thread.
|
public static final int MAX_THREADS
public static final int MAX_THREADS_MIN
public static final int MAX_SPARE_THREADS
public static final int MIN_SPARE_THREADS
public static final int WORK_WAIT_TIMEOUT
protected ThreadPool.ControlRunnable[] pool
protected ThreadPool.MonitorRunnable monitor
protected int maxThreads
protected int minSpareThreads
protected int maxSpareThreads
protected int currentThreadCount
protected int currentThreadsBusy
protected boolean stopThePool
protected boolean isDaemon
protected java.util.Hashtable threads
protected java.util.Vector listeners
protected java.lang.String name
protected int sequence
protected int threadPriority
public static ThreadPool createThreadPool(boolean jmx)
jmx
- UNUSEDpublic void start()
public ThreadPool.MonitorRunnable getMonitor()
public void setThreadPriority(int threadPriority)
threadPriority
- The new priorityjava.lang.IllegalArgumentException
- If the specified
priority is less than Thread.MIN_PRIORITY or
more than Thread.MAX_PRIORITYpublic int getThreadPriority()
public void setMaxThreads(int maxThreads)
public int getMaxThreads()
public void setMinSpareThreads(int minSpareThreads)
public int getMinSpareThreads()
public void setMaxSpareThreads(int maxSpareThreads)
public int getMaxSpareThreads()
public int getCurrentThreadCount()
public int getCurrentThreadsBusy()
public boolean isDaemon()
public static int getDebug()
public void setDaemon(boolean b)
public boolean getDaemon()
public void setName(java.lang.String name)
public java.lang.String getName()
public int getSequence()
public int incSequence()
public void addThread(java.lang.Thread t, ThreadPool.ControlRunnable cr)
public void removeThread(java.lang.Thread t)
public void addThreadPoolListener(ThreadPool.ThreadPoolListener tpl)
public java.util.Enumeration getThreads()
public void run(java.lang.Runnable r)
public void runIt(ThreadPoolRunnable r)
public void shutdown()
protected void checkSpareControllers()
protected void returnController(ThreadPool.ControlRunnable c)
protected void notifyThreadEnd(ThreadPool.ControlRunnable c)
protected void adjustLimits()
protected void openThreads(int toOpen)
toOpen
- Total number of threads we'll have openpublic java.lang.String threadStatusString()
public java.lang.String[] getThreadStatus()
public java.lang.String[] getThreadParam()
Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.