Class CachedThreadPoolExecutor
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- java.util.concurrent.ThreadPoolExecutor
-
- de.aristaflow.adept2.util.threading.AFThreadPoolExecutor
-
- de.aristaflow.adept2.util.threading.CachedThreadPoolExecutor
-
- All Implemented Interfaces:
Executor
,ExecutorService
- Direct Known Subclasses:
AbstractObjectSpecificExecutor
public class CachedThreadPoolExecutor extends AFThreadPoolExecutor
AThreadPoolExecutor
which comes in two flavours:-
- Creates new threads to run a new task, if the amount of threads is less than the corePoolSize. Core pool threads will be reused and will live until the thread pool is shutdown.
- Creates new threads, if the amount of threads is less than the maxPoolSize. These threads will terminate after 60 seconds, if the workload reduces.
- If there is more work than the amount of maximum threads, the tasks will be put into an unbounded queue.
-
- Creates new threads to run a new task, if the amount of threads is less than the pool size. Pool threads will terminate after being idle for 60 seconds.
- If there is more work than the pool size, the tasks will be put into an unbounded queue.
- The queue is a priority queue which sorts based on a specific comparator.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor
ThreadPoolExecutor.AbortPolicy, ThreadPoolExecutor.CallerRunsPolicy, ThreadPoolExecutor.DiscardOldestPolicy, ThreadPoolExecutor.DiscardPolicy
-
-
Field Summary
Fields Modifier and Type Field Description protected AtomicBoolean
fullSize
Whether the pool (its amount of core threads) is set to the maximum size.protected int
realCoreSize
The normal core size of the pool.protected int
realMaxSize
The maximum size of the pool.protected AtomicInteger
workSize
The amount of work currently in the pool.-
Fields inherited from class de.aristaflow.adept2.util.threading.AFThreadPoolExecutor
activeThreads, completedTasks, HYSTERESIS, submittedTasks
-
-
Constructor Summary
Constructors Constructor Description CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, boolean prestart, Adept2ThreadFactory threadFactory)
Deprecated, for removal: This API element is subject to removal in a future version.CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, boolean prestart, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
Deprecated, for removal: This API element is subject to removal in a future version.CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, boolean prestart, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
Deprecated, for removal: This API element is subject to removal in a future version.CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, boolean prestart, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, Level minLogLevelPoolStatistics)
Deprecated, for removal: This API element is subject to removal in a future version.CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, Adept2ThreadFactory threadFactory)
Creates a newCachedThreadPoolExecutor
with the given initial parameters and default rejected execution handler.CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
Creates a newCachedThreadPoolExecutor
with the designated initial parameters and default rejected execution handler.CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
Creates a newCachedThreadPoolExecutor
with the designated initial parameters and default rejected execution handler.CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, Level minLogLevelPoolStatistics)
Creates a newCachedThreadPoolExecutor
with the designated initial parameters and default rejected execution handler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
afterExecute(Runnable r, Throwable t)
void
execute(Runnable task)
-
Methods inherited from class de.aristaflow.adept2.util.threading.AFThreadPoolExecutor
beforeExecute, logPoolStatistics, newTaskFor, newTaskFor, recalculateLogLimits, setCorePoolSize, setLogExecuteCallStack, setMaximumPoolSize, updateQueueLimit
-
Methods inherited from class java.util.concurrent.ThreadPoolExecutor
allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setKeepAliveTime, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated, toString
-
-
-
-
Field Detail
-
realCoreSize
protected final int realCoreSize
The normal core size of the pool.
-
realMaxSize
protected final int realMaxSize
The maximum size of the pool.
-
fullSize
protected final AtomicBoolean fullSize
Whether the pool (its amount of core threads) is set to the maximum size.
-
workSize
protected final AtomicInteger workSize
The amount of work currently in the pool. If this exceeds the normal core pool size, the core pool size is increased to the maximum size of the pool. If the amount of work goes below the normal core pool size, the core pool size will be reduced again.
-
-
Constructor Detail
-
CachedThreadPoolExecutor
public CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, Adept2ThreadFactory threadFactory)
Creates a newCachedThreadPoolExecutor
with the given initial parameters and default rejected execution handler. The cached thread pool executor increases the corePoolSize to the maxPoolSize if the work load exceeds the amount of core threads. If the work load declines, the corePoolSize will be reduced to the original value.- Parameters:
corePoolSize
- The number of threads to keep in the pool, even if they are idle.maxPoolSize
- The maximum number of threads to allow in the pool.threadFactory
- The factory to use when the executor creates a new thread.
-
CachedThreadPoolExecutor
@Deprecated(since="14.4.0", forRemoval=true) public CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, boolean prestart, Adept2ThreadFactory threadFactory)
Deprecated, for removal: This API element is subject to removal in a future version.Creates a newCachedThreadPoolExecutor
with the given initial parameters and default rejected execution handler. The cached thread pool executor increases the corePoolSize to the maxPoolSize if the work load exceeds the amount of core threads. If the work load declines, the corePoolSize will be reduced to the original value.- Parameters:
corePoolSize
- The number of threads to keep in the pool, even if they are idle.maxPoolSize
- The maximum number of threads to allow in the pool.prestart
- Whether all core threads should be prestarted.threadFactory
- The factory to use when the executor creates a new thread.
-
CachedThreadPoolExecutor
public CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
Creates a newCachedThreadPoolExecutor
with the designated initial parameters and default rejected execution handler. The cached thread pool executor increases the corePoolSize to the maxPoolSize if the work load exceeds the amount of core threads. If the work load declines, the corePoolSize will be reduced to the original value, idle threads will terminate after 60 seconds. If the work load exceeds the pool size, work will be put into a queue.- Parameters:
corePoolSize
- The number of threads to keep in the pool, even if they are idle.maxPoolSize
- The maximum number of threads to allow in the pool.threadFactory
- The factory to use when the executor creates a new thread.queueLimitPoolStatistics
- The amount of tasks in the queue before warnings will be logged. Use-1
to use the default limits.minLogLevelPoolStatistics
- The log level which need to be reached for logging pool statistics. Pool statistics logs with a lower log level will be ignored.
-
CachedThreadPoolExecutor
@Deprecated(since="14.4.0", forRemoval=true) public CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, boolean prestart, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
Deprecated, for removal: This API element is subject to removal in a future version.Creates a newCachedThreadPoolExecutor
with the designated initial parameters and default rejected execution handler. The cached thread pool executor increases the corePoolSize to the maxPoolSize if the work load exceeds the amount of core threads. If the work load declines, the corePoolSize will be reduced to the original value, idle threads will terminate after 60 seconds. If the work load exceeds the pool size, work will be put into a queue.- Parameters:
corePoolSize
- The number of threads to keep in the pool, even if they are idle.maxPoolSize
- The maximum number of threads to allow in the pool.prestart
- Whether all core threads should be prestarted.threadFactory
- The factory to use when the executor creates a new thread.queueLimitPoolStatistics
- The amount of tasks in the queue before warnings will be logged. Use-1
to use the default limits.minLogLevelPoolStatistics
- The log level which need to be reached for logging pool statistics. Pool statistics logs with a lower log level will be ignored.
-
CachedThreadPoolExecutor
public CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, Level minLogLevelPoolStatistics)
Creates a newCachedThreadPoolExecutor
with the designated initial parameters and default rejected execution handler. The cached thread pool executor increases the corePoolSize to the maxPoolSize if the work load exceeds the amount of core threads. If the work load declines, the corePoolSize will be reduced to the original value, idle threads will terminate after 60 seconds. If the work load exceeds the pool size, work will be put into a queue. The queue itself prioritises work using the designated comparator.- Parameters:
corePoolSize
- The number of threads to keep in the pool, even if they are idle.maxPoolSize
- The maximum number of threads to allow in the pool.comparator
- The comparator used to determine the priority of work.threadFactory
- The factory to use when the executor creates a new thread.minLogLevelPoolStatistics
- The log level which need to be reached for logging pool statistics. Pool statistics logs with a lower log level will be ignored.
-
CachedThreadPoolExecutor
@Deprecated(since="14.4.0", forRemoval=true) public CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, boolean prestart, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, Level minLogLevelPoolStatistics)
Deprecated, for removal: This API element is subject to removal in a future version.Creates a newCachedThreadPoolExecutor
with the designated initial parameters and default rejected execution handler. The cached thread pool executor increases the corePoolSize to the maxPoolSize if the work load exceeds the amount of core threads. If the work load declines, the corePoolSize will be reduced to the original value, idle threads will terminate after 60 seconds. If the work load exceeds the pool size, work will be put into a queue. The queue itself prioritises work using the designated comparator.- Parameters:
corePoolSize
- The number of threads to keep in the pool, even if they are idle.maxPoolSize
- The maximum number of threads to allow in the pool.prestart
- Whether all core threads should be prestarted.comparator
- The comparator used to determine the priority of work.threadFactory
- The factory to use when the executor creates a new thread.minLogLevelPoolStatistics
- The log level which need to be reached for logging pool statistics. Pool statistics logs with a lower log level will be ignored.
-
CachedThreadPoolExecutor
public CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
Creates a newCachedThreadPoolExecutor
with the designated initial parameters and default rejected execution handler. The cached thread pool executor increases the corePoolSize to the maxPoolSize if the work load exceeds the amount of core threads. If the work load declines, the corePoolSize will be reduced to the original value, idle threads will terminate after 60 seconds. If the work load exceeds the pool size, work will be put into a queue. The queue itself prioritises work using the designated comparator.- Parameters:
corePoolSize
- The number of threads to keep in the pool, even if they are idle.maxPoolSize
- The maximum number of threads to allow in the pool.comparator
- The comparator used to determine the priority of work.threadFactory
- The factory to use when the executor creates a new thread.queueLimitPoolStatistics
- The amount of tasks in the queue before warnings will be logged. Use-1
to use the default limits.minLogLevelPoolStatistics
- The log level which need to be reached for logging pool statistics. Pool statistics logs with a lower log level will be ignored.
-
CachedThreadPoolExecutor
@Deprecated(since="14.4.0", forRemoval=true) public CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, boolean prestart, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics)
Deprecated, for removal: This API element is subject to removal in a future version.Creates a newCachedThreadPoolExecutor
with the designated initial parameters and default rejected execution handler. The cached thread pool executor increases the corePoolSize to the maxPoolSize if the work load exceeds the amount of core threads. If the work load declines, the corePoolSize will be reduced to the original value, idle threads will terminate after 60 seconds. If the work load exceeds the pool size, work will be put into a queue. The queue itself prioritises work using the designated comparator.- Parameters:
corePoolSize
- The number of threads to keep in the pool, even if they are idle.maxPoolSize
- The maximum number of threads to allow in the pool.prestart
- Whether all core threads should be prestarted.comparator
- The comparator used to determine the priority of work.threadFactory
- The factory to use when the executor creates a new thread.queueLimitPoolStatistics
- The amount of tasks in the queue before warnings will be logged. Use-1
to use the default limits.minLogLevelPoolStatistics
- The log level which need to be reached for logging pool statistics. Pool statistics logs with a lower log level will be ignored.
-
-
Method Detail
-
execute
public void execute(Runnable task)
- Specified by:
execute
in interfaceExecutor
- Overrides:
execute
in classAFThreadPoolExecutor
-
afterExecute
protected void afterExecute(Runnable r, Throwable t)
- Overrides:
afterExecute
in classAFThreadPoolExecutor
-
-