|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.mortbay.util.ThreadPool
A pool of threads.
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. By default there is no maximum pool size. 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.
Inner Class Summary | |
static class |
ThreadPool.PoolThread
Pool Thread run class. |
Field Summary | |
static int |
__nullLockChecks
The number of times a null lock check should synchronize. |
Constructor Summary | |
ThreadPool()
|
|
ThreadPool(java.lang.String name)
|
Method Summary | |
void |
destroy()
Destroy the ThreadPool. |
int |
getIdleThreads()
Get the number of threads in the pool. |
protected java.lang.Object |
getJob(int idleTimeoutMs)
Get a job. |
int |
getMaxIdleTimeMs()
Get the maximum thread idle time. |
int |
getMaxSize()
Deprecated. use getMaxThreads |
int |
getMaxStopTimeMs()
Get the maximum thread stop time. |
int |
getMaxThreads()
Set the maximum number of threads. |
int |
getMinSize()
Deprecated. use getMinThreads |
int |
getMinThreads()
Get the minimum number of threads. |
java.lang.String |
getName()
|
int |
getSize()
Deprecated. use getThreads |
java.lang.Class |
getThreadClass()
|
int |
getThreads()
Get the number of threads in the pool. |
protected void |
handle(java.lang.Object job)
Handle a job. |
void |
initialize(java.lang.Object o)
Not required. |
boolean |
isDestroyed()
|
boolean |
isStarted()
Is the pool running jobs. |
void |
join()
Join the ThreadPool. |
void |
run(java.lang.Object job)
Run job. |
void |
setMaxIdleTimeMs(int maxIdleTimeMs)
Set the maximum thread idle time. |
void |
setMaxSize(int maxThreads)
Deprecated. use setMaxThreads |
void |
setMaxStopTimeMs(int maxStopTimeMs)
Set the maximum thread stop time. |
void |
setMaxThreads(int maxThreads)
Set the maximum number of threads. |
void |
setMinSize(int minThreads)
Deprecated. use setMinThreads |
void |
setMinThreads(int minThreads)
Set the minimum number of threads. |
void |
setName(java.lang.String name)
|
void |
setThreadClass(java.lang.Class threadClass)
Set the Thread class. |
void |
start()
Start the LifeCycle. |
void |
stop()
Stop the ThreadPool. |
protected boolean |
stopJob(java.lang.Thread thread,
java.lang.Object job)
Stop a job. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static int __nullLockChecks
Constructor Detail |
public ThreadPool()
public ThreadPool(java.lang.String name)
Method Detail |
public java.lang.String getName()
public void setName(java.lang.String name)
name
- public void setThreadClass(java.lang.Class threadClass) throws java.lang.IllegalStateException
threadClas
- The classjava.lang.IllegalStateException
- If the pool has already
been started.public java.lang.Class getThreadClass()
protected void handle(java.lang.Object job) throws java.lang.InterruptedException
job
- The Job to handle. If it implements Runnable,
this implementation calls run().public boolean isStarted()
isStarted
in interface LifeCycle
public boolean isDestroyed()
isDestroyed
in interface LifeCycle
org.mortbay.util.LifeCycle
public int getThreads()
public int getIdleThreads()
public int getMinThreads()
public void setMinThreads(int minThreads)
minThreads
- minimum number of threadspublic int getMaxThreads()
public void setMaxThreads(int maxThreads)
maxThreads
- maximum number of threads.public int getMaxIdleTimeMs()
public void setMaxIdleTimeMs(int maxIdleTimeMs)
maxIdleTimeMs
- Max idle time in ms.public int getMaxStopTimeMs()
public void setMaxStopTimeMs(int maxStopTimeMs)
maxIdleTimeMs
- Max stop time in ms.public void initialize(java.lang.Object o)
o
- ignored.public void start() throws java.lang.Exception
LifeCycle
start
in interface LifeCycle
org.mortbay.util.LifeCycle
java.lang.Exception
- An arbitrary exception may be thrown.public void stop() throws java.lang.InterruptedException
stop
in interface LifeCycle
protected boolean stopJob(java.lang.Thread thread, java.lang.Object job)
thread
- The Thread running the jobjob
- The job, or null if it cannot be determinedpublic void destroy()
destroy
in interface LifeCycle
public final void join() throws java.lang.InterruptedException
java.lang.InterruptedException
- protected java.lang.Object getJob(int idleTimeoutMs) throws java.lang.InterruptedException, java.io.InterruptedIOException
idleTimeoutMs
- The timout to wait for a job.java.lang.InterruptedException
- java.io.InterruptedIOException
- public void run(java.lang.Object job) throws java.lang.InterruptedException
job.
- If the job is derived from Runnable, the run method
is called, otherwise it is passed as the argument to the handle
method.public int getSize()
public int getMinSize()
public void setMinSize(int minThreads)
minThreads
- minimum number of threadspublic int getMaxSize()
public void setMaxSize(int maxThreads)
maxThreads
- maximum number of threads.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |