|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--net.larsan.urd.util.ThreadPool
The thread pool is an abstract pool of thread. The subclasses must specify four methods: creation and
destruction of single threads and handling before and after execution. This makes it possible to
use the pool with subclasses of Thread and a possibility to set thread local
variables such as class loaders before execution.
Users of the thread pool simply pass a Runnable into the execute method and form that
point on the pool controls the execution of the code.
This thread pool can be started with a minimum and maximum of threads. The minimum threads will
be created on pool startup. The maximum number is optional and specifies the absolute maximum
number of threads possible. Further tweaking is possible with the setExceedingThreadTTL
method which sets the timeout for unused threads when the pool exceeds the minimum pool size, and the
setExcecuteQueueTimeout which allows the pool to wait for free threads when a request to
execute is made but the max number of threads is already reached.
| Constructor Summary | |
ThreadPool(java.lang.String name)
Contruct thread pool. |
|
ThreadPool(java.lang.String name,
int minimum)
Contruct thread pool given a minimum number of threads. |
|
ThreadPool(java.lang.String name,
int minimum,
int maximum)
Contruct thread pool given a minimum and a maximum number of threads. |
|
| Method Summary | |
protected void |
afterExecution(java.lang.Runnable target)
This method is called just after a target is executed by the thread pool by the thread that will execute the target. |
protected void |
beforeExecution(java.lang.Runnable target)
This method is called just before a target is executed by the thread pool by the thread that will execute the target. |
void |
close()
Close the pool. |
protected java.lang.Thread |
createThread(java.lang.Runnable handle)
Create a new thread. |
protected void |
destroyThread(java.lang.Thread thread)
Destroy a thread. |
void |
execute(java.lang.Runnable target)
Execute a runnable. |
long |
getExcecuteQueueTimeout()
Get the time an execution request may wait if there is no threads available before throwing an ExecutionDeniedException. |
int |
getMaximumSize()
Get the maximum size of this thread pool. |
int |
getMinimumSize()
Get the minimum size of this thread pool. |
long |
getThreadTTL()
Get the time in milliseconds a thread will live if not used and the pool size is above it's minimum size. |
void |
setExcecuteQueueTimeout(long millis)
Get the time an execution request may wait if there is no threads available before throwing an ExecutionDeniedException. |
void |
setMaximumSize(int maximum)
Set the maximum size of this thread pool. |
void |
setThreadTTL(long millis)
Set the time in milliseconds a thread will live if not used and the pool size is above it's minimum size. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public ThreadPool(java.lang.String name,
int minimum,
int maximum)
The default thread TTL is 30 minutes.
name - The pool name, used for all new threadsminimum - The minimum number of threads in the pool, must be above zeromaximum - The maximum number of threads in the pool, -1 to disable
public ThreadPool(java.lang.String name,
int minimum)
The default thread TTL is 30 minutes.
name - The pool name, used for new threadsminimum - The minimum number of threads in the pool, must be above zeropublic ThreadPool(java.lang.String name)
name - The pool name, used for new threads| Method Detail |
public void execute(java.lang.Runnable target)
throws java.lang.IllegalStateException
run method. Should the pool be full, be closed or get an internal error a IllegalStateException
will be thrown.
execute in interface Executortarget - Runnable to execute by a thread from the pool
java.lang.IllegalStateException - If the pool does not accept the targetpublic void close()
public long getExcecuteQueueTimeout()
ExecutionDeniedException. This returns -1 if the wait is disabled.
public void setExcecuteQueueTimeout(long millis)
ExecutionDeniedException. The wait can be disabled by setting the
value to -1.
millis - A millisecond value representing the wait, -1 for disablingpublic long getThreadTTL()
public void setThreadTTL(long millis)
public int getMinimumSize()
public int getMaximumSize()
public void setMaximumSize(int maximum)
throws java.lang.IllegalArgumentException
IllegalArgumentException will be thrown if
the value is lower than the minimum size of the pool or negative, except for -1 wich disables
the max size.
java.lang.IllegalArgumentExceptionprotected java.lang.Thread createThread(java.lang.Runnable handle)
handle - Runnable thread handle to use in creationprotected void destroyThread(java.lang.Thread thread)
thread - The thread that leaves the pool, never nullprotected void beforeExecution(java.lang.Runnable target)
target - Runnable just to be executedprotected void afterExecution(java.lang.Runnable target)
target - Runnable just executed
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||