Class BoundedThreadPool

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

    public final class BoundedThreadPool
    extends java.util.concurrent.ThreadPoolExecutor
    Implementation of ThreadPoolExecutor that bounds the work queue.

    When a new job would exceed the queue bound, the job is run on the caller's thread rather than on a thread from the pool.

    • 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
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void afterExecute​(java.lang.Runnable r, java.lang.Throwable t)  
      protected void beforeExecute​(java.lang.Thread t, java.lang.Runnable r)  
      void execute​(java.lang.Runnable command)  
      static BoundedThreadPool newFixedThreadPool​(int numberOfThreads, java.util.concurrent.ThreadFactory threadFactory)
      Returns a fixed-size, bounded executor service.
      static BoundedThreadPool newSingleThreadExecutor​(java.util.concurrent.ThreadFactory threadFactory)
      Returns a single-thread, bounded executor service.
      java.util.concurrent.Future<?> submit​(java.lang.Runnable task)  
      <T> java.util.concurrent.Future<T> submit​(java.lang.Runnable task, T result)  
      <T> java.util.concurrent.Future<T> submit​(java.util.concurrent.Callable<T> task)  
      • Methods 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, setCorePoolSize, setKeepAliveTime, setMaximumPoolSize, setRejectedExecutionHandler, setThreadFactory, shutdown, shutdownNow, terminated, toString
      • Methods inherited from class java.util.concurrent.AbstractExecutorService

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

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

      • newSingleThreadExecutor

        public static BoundedThreadPool newSingleThreadExecutor​(java.util.concurrent.ThreadFactory threadFactory)
        Returns a single-thread, bounded executor service.
        Parameters:
        threadFactory - thread factory for the worker thread.
        Returns:
        the bounded thread pool
      • newFixedThreadPool

        public static BoundedThreadPool newFixedThreadPool​(int numberOfThreads,
                                                           java.util.concurrent.ThreadFactory threadFactory)
        Returns a fixed-size, bounded executor service.
        Parameters:
        numberOfThreads - number of threads in the pool
        threadFactory - thread factory for the worker threads.
        Returns:
        the bounded thread pool
      • submit

        public java.util.concurrent.Future<?> submit​(java.lang.Runnable task)
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
        Overrides:
        submit in class java.util.concurrent.AbstractExecutorService
      • submit

        public <T> java.util.concurrent.Future<T> submit​(java.lang.Runnable task,
                                                         T result)
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
        Overrides:
        submit in class java.util.concurrent.AbstractExecutorService
      • 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
      • submit

        public <T> java.util.concurrent.Future<T> submit​(java.util.concurrent.Callable<T> task)
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
        Overrides:
        submit in class java.util.concurrent.AbstractExecutorService
      • beforeExecute

        protected void beforeExecute​(java.lang.Thread t,
                                     java.lang.Runnable r)
        Overrides:
        beforeExecute 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