Class DynamicallySizedThreadPoolExecutor

  • All Implemented Interfaces:
    java.util.concurrent.Executor, java.util.concurrent.ExecutorService

    public class DynamicallySizedThreadPoolExecutor
    extends java.util.concurrent.ThreadPoolExecutor
    This is an instance of ThreadPoolExecutor which behaves how one would expect it to, even when faced with an unlimited queue. Unlike the default ThreadPoolExecutor, it will add new Threads up to maximumPoolSize when there is lots of pending work, rather than only when the queue is full (which it often never will be, especially for unlimited queues)
    Author:
    Nick Burch
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.util.concurrent.ThreadPoolExecutor

        java.util.concurrent.ThreadPoolExecutor.AbortPolicy, java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy, java.util.concurrent.ThreadPoolExecutor.DiscardPolicy
    • Constructor Summary

      Constructors 
      Constructor Description
      DynamicallySizedThreadPoolExecutor​(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue)  
      DynamicallySizedThreadPoolExecutor​(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue, java.util.concurrent.RejectedExecutionHandler handler)  
      DynamicallySizedThreadPoolExecutor​(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue, java.util.concurrent.ThreadFactory threadFactory)  
      DynamicallySizedThreadPoolExecutor​(int corePoolSize, int maximumPoolSize, long keepAliveTime, java.util.concurrent.TimeUnit unit, java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue, java.util.concurrent.ThreadFactory threadFactory, java.util.concurrent.RejectedExecutionHandler handler)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void afterExecute​(java.lang.Runnable r, java.lang.Throwable t)  
      void execute​(java.lang.Runnable command)  
      void setCorePoolSize​(int corePoolSize)  
      • Methods inherited from class java.util.concurrent.ThreadPoolExecutor

        allowCoreThreadTimeOut, allowsCoreThreadTimeOut, awaitTermination, beforeExecute, finalize, getActiveCount, getCompletedTaskCount, getCorePoolSize, getKeepAliveTime, getLargestPoolSize, getMaximumPoolSize, getPoolSize, getQueue, getRejectedExecutionHandler, getTaskCount, getThreadFactory, isShutdown, isTerminated, isTerminating, prestartAllCoreThreads, prestartCoreThread, purge, remove, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated, toString
      • Methods inherited from class java.util.concurrent.AbstractExecutorService

        invokeAll, invokeAll, invokeAny, invokeAny, newTaskFor, newTaskFor, submit, submit, submit
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DynamicallySizedThreadPoolExecutor

        public DynamicallySizedThreadPoolExecutor​(int corePoolSize,
                                                  int maximumPoolSize,
                                                  long keepAliveTime,
                                                  java.util.concurrent.TimeUnit unit,
                                                  java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue,
                                                  java.util.concurrent.RejectedExecutionHandler handler)
      • DynamicallySizedThreadPoolExecutor

        public DynamicallySizedThreadPoolExecutor​(int corePoolSize,
                                                  int maximumPoolSize,
                                                  long keepAliveTime,
                                                  java.util.concurrent.TimeUnit unit,
                                                  java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue,
                                                  java.util.concurrent.ThreadFactory threadFactory,
                                                  java.util.concurrent.RejectedExecutionHandler handler)
      • DynamicallySizedThreadPoolExecutor

        public DynamicallySizedThreadPoolExecutor​(int corePoolSize,
                                                  int maximumPoolSize,
                                                  long keepAliveTime,
                                                  java.util.concurrent.TimeUnit unit,
                                                  java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue,
                                                  java.util.concurrent.ThreadFactory threadFactory)
      • DynamicallySizedThreadPoolExecutor

        public DynamicallySizedThreadPoolExecutor​(int corePoolSize,
                                                  int maximumPoolSize,
                                                  long keepAliveTime,
                                                  java.util.concurrent.TimeUnit unit,
                                                  java.util.concurrent.BlockingQueue<java.lang.Runnable> workQueue)
    • Method Detail

      • setCorePoolSize

        public void setCorePoolSize​(int corePoolSize)
        Overrides:
        setCorePoolSize in class java.util.concurrent.ThreadPoolExecutor
      • execute

        public void execute​(java.lang.Runnable command)
        Specified by:
        execute in interface java.util.concurrent.Executor
        Overrides:
        execute in class java.util.concurrent.ThreadPoolExecutor
      • afterExecute

        protected void afterExecute​(java.lang.Runnable r,
                                    java.lang.Throwable t)
        Overrides:
        afterExecute in class java.util.concurrent.ThreadPoolExecutor