Package rma.util.concurrent
Class DynamicallySizedThreadPool
java.lang.Object
java.util.concurrent.AbstractExecutorService
java.util.concurrent.ThreadPoolExecutor
rma.util.concurrent.DynamicallySizedThreadPool
- All Implemented Interfaces:
Executor
,ExecutorService
This class extends ThreadPoolExecutor to support dynamically sized thread pools. The
ThreadPoolExecutor only supports dynamic resizing of the thread pool when it has a limited size
queue. This means that eventually the queue would fill up, and the threads would fill up, and
we'd no longer be able to submit Runnables onto the threads, and the Runnable gets handed off to
the RejectionHandler.
To bypass this, we're throttling up the corePoolSize to a point where we create enough threads to
handle the Runnable throughput, or max out the threads. Once the Runnables have all completed
their job, the corePoolSize is reduced to the minimumPoolSize handed to the constructor. After a
period of time, the extra threads will die off (keepAliveTime, and unit from ctor).
The strategy for adjusting the corePoolSize is that when a Runnable is queued up due to
insufficient Threads the corePoolSize is increased to pick up all new Runnables. The corePoolSize
does not go down until all runnables have been completed, and the corePoolSize is reset to the
minimumPoolSize. This forces the corePoolSize to the maximumPoolSize very quickly when a huge
influx of Runnables are submitted, but when a steady stream of quick Runnables are submitted, it
will maintain a balanced size to fit the needs of the submitted Runnables.
Before modifying this code, please contact Ryan Miles and Peter Morris.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
-
Constructor Summary
ConstructorsConstructorDescriptionDynamicallySizedThreadPool
(int minimumPoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory) DynamicallySizedThreadPool
(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler) -
Method Summary
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated, toString
Methods inherited from class java.util.concurrent.AbstractExecutorService
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
-
Constructor Details
-
DynamicallySizedThreadPool
public DynamicallySizedThreadPool(int minimumPoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory) -
DynamicallySizedThreadPool
public DynamicallySizedThreadPool(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler)
-
-
Method Details
-
afterExecute
- Overrides:
afterExecute
in classThreadPoolExecutor
-
execute
- Specified by:
execute
in interfaceExecutor
- Overrides:
execute
in classThreadPoolExecutor
-