Class CachedThreadPoolExecutor

  • All Implemented Interfaces:
    Executor, ExecutorService
    Direct Known Subclasses:
    AbstractObjectSpecificExecutor

    public class CachedThreadPoolExecutor
    extends AFThreadPoolExecutor
    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.
    • 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 new CachedThreadPoolExecutor 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 new CachedThreadPoolExecutor 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 new CachedThreadPoolExecutor 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 new CachedThreadPoolExecutor 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 new CachedThreadPoolExecutor 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 new CachedThreadPoolExecutor 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 new CachedThreadPoolExecutor 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 new CachedThreadPoolExecutor 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.