public class ScalingThreadPoolExecutor extends ThreadPoolExecutor
ThreadPoolExecutor that internally uses a ScalingLinkedBlockingQueue to manage scheduled tasks.
This allows us to manage a dynamically sized thread pool that actually spawns new threads when the pool still allows
for it.
Additionally, this implementation keeps track of the current number of active threads by using an
AtomicInteger counter, rather than querying its list of worker threads.
For further information, see this blog post.
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy| Constructor and Description |
|---|
ScalingThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterExecute(Runnable r,
Throwable t) |
protected void |
beforeExecute(Thread t,
Runnable r) |
int |
getActiveCount() |
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, execute, finalize, 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, toStringinvokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submitpublic ScalingThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit)
public int getActiveCount()
getActiveCount in class ThreadPoolExecutorprotected void beforeExecute(Thread t, Runnable r)
beforeExecute in class ThreadPoolExecutorprotected void afterExecute(Runnable r, Throwable t)
afterExecute in class ThreadPoolExecutorCopyright © 2019. All rights reserved.