public class ScalingThreadPoolExecutor extends ThreadPoolExecutor
ExecutorService
that executes each submitted task using one of
possibly several pooled threads. It also scales up the number of threads in
the pool if the number of submissions exceeds the core size of the pool. The
pool can scale up to the specified maximum pool size.
If the number of submissions exceeds the sum of the core and maximum size of
the thread pool, the submissions are then handled by the provided
RejectedExecutionHandler
.
If the overflowing submissions need to be handled,
BufferedThreadPoolExecutorCompletionService
can be used to buffer up
overflowing submissions for later submission as threads become available.ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
Constructor and Description |
---|
ScalingThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
int workerQueueSize)
Constructor.
|
afterExecute, allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, execute, 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
invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
public ScalingThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, int workerQueueSize)
corePoolSize
- the number of threads which will be considered as "core". If core
thread timeout is not enabled, then this will be the minimum
number of threads, always. With core timeout enabled, then this
will be the number of threads spun up to handle incoming work
regardless of worker queue size.maximumPoolSize
- the maximum number of threads which can be spawned when an
ExecutorService
encounters a failure inserting into the
work queue. These threads are not spawned to handle entries into
the work queue; they are only spawned if the queue fills and a
RejectedExecutionHandler
is invoked.keepAliveTime
- the TTL for core threadsunit
- the time unit for core threadsworkerQueueSize
- the size of the worker queue. The threads specified by
ThreadPoolExecutor.getMaximumPoolSize()
will only be created if the worker
queue is exhausted.Copyright © 2022 Apache Software Foundation. All rights reserved.