public class

ConstrainedExecutorService

extends AbstractExecutorService
java.lang.Object
   ↳ java.util.concurrent.AbstractExecutorService
     ↳ com.facebook.common.executors.ConstrainedExecutorService
Known Direct Subclasses

Class Overview

A java.util.concurrent.ExecutorService that delegates to an existing Executor but constrains the number of concurrently executing tasks to a pre-configured value.

Summary

Public Constructors
ConstrainedExecutorService(String name, int maxConcurrency, Executor executor, BlockingQueue<Runnable> workQueue)
Creates a new ConstrainedExecutorService.
Public Methods
boolean awaitTermination(long timeout, TimeUnit unit)
void execute(Runnable runnable)
Submit a task to be executed in the future.
boolean isIdle()
Determine whether or not the queue is idle.
boolean isShutdown()
boolean isTerminated()
static ConstrainedExecutorService newConstrainedExecutor(String name, int maxConcurrency, int queueSize, Executor executor)
Factory method to create a new ConstrainedExecutorService with an unbounded LinkedBlockingQueue queue.
void shutdown()
List<Runnable> shutdownNow()
[Expand]
Inherited Methods
From class java.util.concurrent.AbstractExecutorService
From class java.lang.Object
From interface java.util.concurrent.Executor
From interface java.util.concurrent.ExecutorService

Public Constructors

public ConstrainedExecutorService (String name, int maxConcurrency, Executor executor, BlockingQueue<Runnable> workQueue)

Creates a new ConstrainedExecutorService.

Parameters
name Friendly name to identify the executor in logging and reporting.
maxConcurrency Maximum number of tasks to execute in parallel on the delegate executor.
executor Delegate executor for actually running tasks.
workQueue Queue to hold Runnables for eventual execution.

Public Methods

public boolean awaitTermination (long timeout, TimeUnit unit)

Throws
InterruptedException

public void execute (Runnable runnable)

Submit a task to be executed in the future.

Parameters
runnable The task to be executed.

public boolean isIdle ()

Determine whether or not the queue is idle.

Returns
  • true if there is no work being executed and the work queue is empty, false otherwise.

public boolean isShutdown ()

public boolean isTerminated ()

public static ConstrainedExecutorService newConstrainedExecutor (String name, int maxConcurrency, int queueSize, Executor executor)

Factory method to create a new ConstrainedExecutorService with an unbounded LinkedBlockingQueue queue.

Parameters
name Friendly name to identify the executor in logging and reporting.
maxConcurrency Maximum number of tasks to execute in parallel on the delegate executor.
queueSize Number of items that can be queued before new submissions are rejected.
executor Delegate executor for actually running tasks.
Returns
  • new ConstrainedExecutorService instance.

public void shutdown ()

public List<Runnable> shutdownNow ()