|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectariba.util.core.ThreadPool
public class ThreadPool
Standard non-extensible thread pool implememtation on top of queue. Users provide Runnable implementations and call execute.
The pool is constituted of Threads retrieve from a ThreadFactory. Normally, the number of threads created cannot exceed a specified number of threads, and new threads are created if necessary until the limit is reached.
Each thread pool is configured with a RejectedExecutionHandler
. When the user call execute, the
runnable is added to a queue and a thread is notified. If all
threads are busy, then one will be added until the thread size
limit is reached. When this happens, outstanding runnables are
queued up. When the queue reaches its (configurable) capacity, the
RejectedExecutionHandler will be called upon to handle the
situation.
At present there are 2 handlers:
DefaultRejectedExecutionHandler
simply drops the runnable
and throws a RejectedExecutionException
.ThreadPoolRejectedExecutionHandler
will increaese the
queue size by roughly 10% to accommodate the new runnables while simultaneously
add more threads regardless of the number of threads already created to
reduce the queue size.Pooled threads remaining idle for longer than the specified time out, will be terminated. A timeout of 0 will result in no idle threads being terminated.
Based on the above discussion, we can arrive at the following guidelines:
Constructor Summary | |
---|---|
ThreadPool(java.lang.String name,
ThreadManager threadManager)
Creates a new ThreadPool starting 1 thread and containing up to 5 threads. |
|
ThreadPool(java.lang.String name,
ThreadManager threadManager,
int minThreads,
int maxThreads,
long timeout,
int queueCapacity,
java.lang.String handlerClassName)
Creates a new ThreadPool. |
Method Summary | |
---|---|
void |
execute(java.lang.Runnable command)
Retrieves a thread from the pool and have it execute the given runnable. |
int |
getMaxThreadCount()
Returns the configured max thread limit. |
ThreadPoolMonitor |
getMonitor()
|
int |
getQueueSize()
Returns the number of objects waiting in the queue |
int |
getThreadCount()
Returns the size of the ThreadPool |
void |
setMonitor(ThreadPoolMonitor monitor)
not synchronized, last one wins |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ThreadPool(java.lang.String name, ThreadManager threadManager)
name
- the name used for the threadsthreadManager
- the ThreadManager used to manage the threadspublic ThreadPool(java.lang.String name, ThreadManager threadManager, int minThreads, int maxThreads, long timeout, int queueCapacity, java.lang.String handlerClassName)
name
- the name used for the threadsthreadManager
- the ThreadManager used to manage the threadsminThreads
- the number of threads to start withmaxThreads
- the maximum number of threads managed by the pooltimeout
- the maximum time a thread remains inactivequeueCapacity
- the size of the queue to hold the runnables. Note
that it is possible for the queue to grow beyond this initial capacity.handlerClassName
- the name of the handling class. If null
DefaultRejectedExecutionHandler
will be used.Method Detail |
---|
public void execute(java.lang.Runnable command)
execute
in interface Executor
command
- the task to be executed
RejectedExecutionException
- if the execution is rejected.public void setMonitor(ThreadPoolMonitor monitor)
public ThreadPoolMonitor getMonitor()
public int getThreadCount()
public int getQueueSize()
public int getMaxThreadCount()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |