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
A
ThreadPoolExecutor 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
FieldsModifier and TypeFieldDescriptionprotected final AtomicBooleanWhether the pool (its amount of core threads) is set to the maximum size.protected final intThe normal core size of the pool.protected final intThe maximum size of the pool.protected final AtomicIntegerThe amount of work currently in the pool.Fields inherited from class de.aristaflow.adept2.util.threading.AFThreadPoolExecutor
activeThreads, completedTasks, HYSTERESIS, submittedTasks -
Constructor Summary
ConstructorsConstructorDescriptionCachedThreadPoolExecutor(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 newCachedThreadPoolExecutorwith the given initial parameters and default rejected execution handler.CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, Adept2ThreadFactory threadFactory, int queueLimitPoolStatistics, Level minLogLevelPoolStatistics) Creates a newCachedThreadPoolExecutorwith 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 newCachedThreadPoolExecutorwith the designated initial parameters and default rejected execution handler.CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, Comparator<? super Runnable> comparator, Adept2ThreadFactory threadFactory, Level minLogLevelPoolStatistics) Creates a newCachedThreadPoolExecutorwith the designated initial parameters and default rejected execution handler. -
Method Summary
Methods inherited from class de.aristaflow.adept2.util.threading.AFThreadPoolExecutor
beforeExecute, logPoolStatistics, newTaskFor, newTaskFor, recalculateLogLimits, setCorePoolSize, setLogExecuteCallStack, setMaximumPoolSize, updateQueueLimitMethods 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 Details
-
realCoreSize
protected final int realCoreSizeThe normal core size of the pool. -
realMaxSize
protected final int realMaxSizeThe maximum size of the pool. -
fullSize
Whether the pool (its amount of core threads) is set to the maximum size. -
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 Details
-
CachedThreadPoolExecutor
public CachedThreadPoolExecutor(int corePoolSize, int maxPoolSize, Adept2ThreadFactory threadFactory) Creates a newCachedThreadPoolExecutorwith 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 newCachedThreadPoolExecutorwith 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 newCachedThreadPoolExecutorwith 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-1to 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 newCachedThreadPoolExecutorwith 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-1to 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 newCachedThreadPoolExecutorwith 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 newCachedThreadPoolExecutorwith 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 newCachedThreadPoolExecutorwith 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-1to 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 newCachedThreadPoolExecutorwith 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-1to 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 Details
-
execute
- Specified by:
executein interfaceExecutor- Overrides:
executein classAFThreadPoolExecutor
-
afterExecute
- Overrides:
afterExecutein classAFThreadPoolExecutor
-
CachedThreadPoolExecutor(int, int, Adept2ThreadFactory)instead.