Class ThreadPool

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

    public class ThreadPool
    extends java.util.concurrent.ThreadPoolExecutor
    An internal implementation of ThreadPoolExecutor that additionally handles the submission of background(Callable) tasks at a lower priority and with more limited slots.
    • 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
      ThreadPool()  
      ThreadPool​(int minThreads, int maxThreads, long msTimeout, int backgroundThreads, long backgroundTimeout)  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      protected void afterExecute​(java.lang.Runnable r, java.lang.Throwable t)
      Standard ThreadPoolExecutor extension point which checks for the BackgroundFutureTask marker and releases a slot in the maxBackground Semaphore.
      <T> java.util.concurrent.Future<T> background​(java.util.concurrent.Callable<T> callable)
      Schedule a task in one of the limited background slots.
      java.util.concurrent.ExecutorService getExecutor()
      Deprecated.
      protected <T> java.util.concurrent.RunnableFuture<T> newTaskFor​(java.util.concurrent.Callable<T> callable)
      Overrides ThreadPoolExecutor to return our own instance of FutureTask so that we have a marker for when the background activity is completed in afterExecute(Runnable, Throwable).
      • Methods inherited from class java.util.concurrent.ThreadPoolExecutor

        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, submit, submit, submit
      • Methods inherited from class java.lang.Object

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

      • ThreadPool

        public ThreadPool()
      • ThreadPool

        public ThreadPool​(int minThreads,
                          int maxThreads,
                          long msTimeout,
                          int backgroundThreads,
                          long backgroundTimeout)
    • Method Detail

      • getExecutor

        @Deprecated
        public java.util.concurrent.ExecutorService getExecutor()
        Deprecated.
        Returns this. Previously ThreadPool was not itself an ExecutorService and returned a delegate instead, most typically in a Spring configuration.
      • background

        public <T> java.util.concurrent.Future<T> background​(java.util.concurrent.Callable<T> callable)
        Schedule a task in one of the limited background slots. If scheduling takes more than hour then the submission will be rejected. Otherwise, the task will run in the same thread pool as both USER and BACKGROUND tasks.
        Parameters:
        callable -
        Returns:
        a future for this task
      • newTaskFor

        protected <T> java.util.concurrent.RunnableFuture<T> newTaskFor​(java.util.concurrent.Callable<T> callable)
        Overrides ThreadPoolExecutor to return our own instance of FutureTask so that we have a marker for when the background activity is completed in afterExecute(Runnable, Throwable). Overriding this method is somewhat non-standard.
        Overrides:
        newTaskFor in class java.util.concurrent.AbstractExecutorService
      • afterExecute

        protected void afterExecute​(java.lang.Runnable r,
                                    java.lang.Throwable t)
        Standard ThreadPoolExecutor extension point which checks for the BackgroundFutureTask marker and releases a slot in the maxBackground Semaphore.
        Overrides:
        afterExecute in class java.util.concurrent.ThreadPoolExecutor