org.mortbay.util
public class ThreadPool extends Object implements LifeCycle, Serializable
Avoids the expense of thread creation by pooling threads after their run methods exit for reuse.
If the maximum pool size is reached, jobs wait for a free thread. Idle threads timeout and terminate until the minimum number of threads are running.
This implementation uses the run(Object) method to place a job on a queue, which is read by the getJob(timeout) method. Derived implementations may specialize getJob(timeout) to obtain jobs from other sources without queing overheads.
Version: $Id: ThreadPool.java,v 1.41 2005/08/13 00:01:28 gregwilkins Exp $
Nested Class Summary | |
---|---|
static class | ThreadPool.PoolThread
Pool Thread class. |
Field Summary | |
---|---|
static String | __DAEMON |
static String | __PRIORITY |
Constructor Summary | |
---|---|
ThreadPool() |
Method Summary | |
---|---|
int | getIdleThreads()
Get the number of idle threads in the pool. |
int | getMaxIdleTimeMs()
Get the maximum thread idle time. |
int | getMaxThreads()
Set the maximum number of threads. |
int | getMinThreads()
Get the minimum number of threads. |
String | getName() |
String | getPoolName() |
int | getThreads()
Get the number of threads in the pool. |
int | getThreadsPriority()
Get the priority of the pool threads.
|
protected void | handle(Object job)
Handle a job. |
boolean | isDaemon()
Delegated to the named or anonymous Pool. |
boolean | isStarted()
Is the pool running jobs.
|
void | join() |
void | run(Object job)
Run job. |
void | setDaemon(boolean daemon)
Delegated to the named or anonymous Pool. |
void | setMaxIdleTimeMs(int maxIdleTimeMs)
Set the maximum thread idle time. |
void | setMaxStopTimeMs(int ms)
Set Max Read Time.
|
void | setMaxThreads(int maxThreads)
Set the maximum number of threads. |
void | setMinThreads(int minThreads)
Set the minimum number of threads. |
void | setName(String name)
Set the Pool name. |
void | setPoolName(String name) |
void | setThreadsPriority(int priority)
Set the priority of the pool threads.
|
void | shrink() |
void | start() |
void | stop()
Stop the ThreadPool. |
protected void | stopJob(Thread thread, Object job)
Stop a Job. |
Returns: Number of threads
See Also: ThreadPool
Returns: Max idle time in ms.
See Also: ThreadPool
Returns: maximum number of threads.
See Also: ThreadPool
Returns: minimum number of threads.
See Also: ThreadPool
Returns: The name of the ThreadPool.
Deprecated: use getName()
Returns: Number of threads
See Also: ThreadPool
Returns: the priority of the pool threads.
Parameters: job The job to execute.
Throws: InterruptedException
Returns: True if start() has been called.
Parameters: job If the job is derived from Runnable, the run method is called, otherwise it is passed as the argument to the handle method.
Parameters: maxIdleTimeMs Max idle time in ms.
See Also: ThreadPool
Deprecated: maxIdleTime is used instead.
Set Max Read Time.Parameters: maxThreads maximum number of threads.
See Also: ThreadPool
Parameters: minThreads minimum number of threads
See Also: ThreadPool
Parameters: name Name of the Pool instance this ThreadPool uses or null for an anonymous private pool.
Deprecated: use setName(String)
Parameters: priority the new thread priority.
Parameters: thread The thread allocated to the job, or null if no thread allocated. job The job object passed to run.