Class MinPooledExecutor

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

    public class MinPooledExecutor
    extends java.util.concurrent.ThreadPoolExecutor
    A pooled executor where the minimum pool size threads are kept alive. This is needed in order for the waitWhenBlocked option to work because of a race condition inside the Executor. The race condition goes something like: RT - Requesting Thread wanting to use the pool LT - Last Thread in the pool RT: Check there are enough free threads to process, yes LT is there, so no need to create a new thread. LT: Times out on the keep alive, LT is destroyed. RT: Try to execute, blocks because there are no available threads. In fact, the pool is now empty which the executor mistakenly inteprets as all of them being in use. Doug Lea says he isn't going to fix. In fact, the version in j2se 1.5 doesn't have this option. In order for this to work, the min pool size must be > 0.
    Version:
    $Revision$
    • 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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int keepAliveSize
      The number of threads to keep alive threads
    • Constructor Summary

      Constructors 
      Constructor Description
      MinPooledExecutor​(int poolSize)
      Construct a new executor
      MinPooledExecutor​(java.util.concurrent.BlockingQueue queue, int poolSize)
      Construct a new executor
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getKeepAliveSize()  
      void setKeepAliveSize​(int keepAliveSize)  
      • Methods inherited from class java.util.concurrent.ThreadPoolExecutor

        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
      • 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
    • Field Detail

      • keepAliveSize

        protected int keepAliveSize
        The number of threads to keep alive threads
    • Constructor Detail

      • MinPooledExecutor

        public MinPooledExecutor​(int poolSize)
        Construct a new executor
        Parameters:
        poolSize - the maximum pool size
      • MinPooledExecutor

        public MinPooledExecutor​(java.util.concurrent.BlockingQueue queue,
                                 int poolSize)
        Construct a new executor
        Parameters:
        queue - the queue for any requests
        poolSize - the maximum pool size
    • Method Detail

      • getKeepAliveSize

        public int getKeepAliveSize()
        Returns:
        the number of threads to keep alive
      • setKeepAliveSize

        public void setKeepAliveSize​(int keepAliveSize)
        Parameters:
        keepAliveSize - the number of threads to keep alive