|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | 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.
Nested Class Summary | |
static class |
ThreadPool.PoolThread
Pool Thread class. |
Field Summary | |
static java.lang.String |
__DAEMON
|
static java.lang.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. |
java.lang.String |
getName()
|
java.lang.String |
getPoolName()
|
int |
getThreads()
Get the number of threads in the pool. |
int |
getThreadsPriority()
Get the priority of the pool threads. |
boolean |
isDaemon()
Delegated to the named or anonymous Pool. |
boolean |
isStarted()
Is the pool running jobs. |
void |
join()
|
void |
run(java.lang.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)
Deprecated. maxIdleTime is used instead. |
void |
setMaxThreads(int maxThreads)
Set the maximum number of threads. |
void |
setMinThreads(int minThreads)
Set the minimum number of threads. |
void |
setName(java.lang.String name)
|
void |
setPoolName(java.lang.String name)
Set the Pool name. |
void |
setThreadsPriority(int priority)
Set the priority of the pool threads. |
void |
shrink()
|
void |
start()
Start the LifeCycle. |
void |
stop()
Stop the ThreadPool. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String __DAEMON
public static final java.lang.String __PRIORITY
Constructor Detail |
public ThreadPool()
Method Detail |
public java.lang.String getName()
public void setName(java.lang.String name)
name
- Name of the ThreadPool to use when naming Threads.public java.lang.String getPoolName()
public void setPoolName(java.lang.String name)
name
- Name of the Pool instance this ThreadPool uses or null for an anonymous private
pool.public boolean isDaemon()
public void setDaemon(boolean daemon)
public boolean isStarted()
isStarted
in interface LifeCycle
public int getThreads()
getIdleThreads()
public int getIdleThreads()
getThreads()
public int getMinThreads()
setMinThreads(int)
public void setMinThreads(int minThreads)
minThreads
- minimum number of threadsgetMinThreads()
public int getMaxThreads()
setMaxThreads(int)
public void setMaxThreads(int maxThreads)
maxThreads
- maximum number of threads.getMaxThreads()
public int getMaxIdleTimeMs()
setMaxIdleTimeMs(int)
public void setMaxIdleTimeMs(int maxIdleTimeMs)
maxIdleTimeMs
- Max idle time in ms.getMaxIdleTimeMs()
public int getThreadsPriority()
public void setThreadsPriority(int priority)
priority
- the new thread priority.public void setMaxStopTimeMs(int ms)
public void start() throws java.lang.Exception
LifeCycle
start
in interface LifeCycle
java.lang.Exception
- An arbitrary exception may be thrown.public void stop() throws java.lang.InterruptedException
stop
in interface LifeCycle
java.lang.InterruptedException
- Stopping a lifecycle is rarely atomic
and may be interrupted by another thread. If this happens
InterruptedException is throw and the component will be in an
indeterminant state and should probably be discarded.public void join()
public void shrink() throws java.lang.InterruptedException
java.lang.InterruptedException
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.
java.lang.InterruptedException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |