Class BlockingThreadPoolExecutorService

java.lang.Object
org.apache.hadoop.thirdparty.com.google.common.collect.ForwardingObject
org.apache.hadoop.thirdparty.com.google.common.util.concurrent.ForwardingExecutorService
org.apache.hadoop.util.SemaphoredDelegatingExecutor
org.apache.hadoop.util.BlockingThreadPoolExecutorService
All Implemented Interfaces:
Executor, ExecutorService

@Private public final class BlockingThreadPoolExecutorService extends SemaphoredDelegatingExecutor
This ExecutorService blocks the submission of new tasks when its queue is already full by using a semaphore. Task submissions require permits, task completions release permits.

This is inspired by this s4 threadpool

  • Method Details

    • newDaemonThreadFactory

      public static ThreadFactory newDaemonThreadFactory(String prefix)
      Get a named ThreadFactory that just builds daemon threads.
      Parameters:
      prefix - name prefix for all threads created from the factory
      Returns:
      a thread factory that creates named, daemon threads with the supplied exception handler and normal priority
    • newInstance

      public static BlockingThreadPoolExecutorService newInstance(int activeTasks, int waitingTasks, long keepAliveTime, TimeUnit unit, String prefixName)
      A thread pool that that blocks clients submitting additional tasks if there are already activeTasks running threads and waitingTasks tasks waiting in its queue.
      Parameters:
      activeTasks - maximum number of active tasks
      waitingTasks - maximum number of waiting tasks
      keepAliveTime - time until threads are cleaned up in unit
      unit - time unit
      prefixName - prefix of name for threads
      Returns:
      BlockingThreadPoolExecutorService.
    • toString

      public String toString()
      Overrides:
      toString in class SemaphoredDelegatingExecutor