Package org.apache.hadoop.util
Class SemaphoredDelegatingExecutor
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
- All Implemented Interfaces:
Executor,ExecutorService
- Direct Known Subclasses:
BlockingThreadPoolExecutorService
@Private
public class SemaphoredDelegatingExecutor
extends org.apache.hadoop.thirdparty.com.google.common.util.concurrent.ForwardingExecutorService
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 a refactoring of BlockingThreadPoolExecutorService; that code
contains the thread pool logic, whereas this isolates the semaphore
and submit logic for use with other thread pools and delegation models.
This is inspired by this s4 threadpool
-
Constructor Summary
ConstructorsConstructorDescriptionSemaphoredDelegatingExecutor(ExecutorService executorDelegatee, int permitCount, boolean fair) Instantiate without collecting executor aquisition duration information.SemaphoredDelegatingExecutor(ExecutorService executorDelegatee, int permitCount, boolean fair, DurationTrackerFactory trackerFactory) Instantiate. -
Method Summary
Modifier and TypeMethodDescriptionprotected ExecutorServicedelegate()voidintGet the number of permits available; guaranteed to be0 <= availablePermits <= size.intTotal number of permits.intGet the number of threads waiting to acquire a permit.invokeAll(Collection<? extends Callable<T>> tasks) invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) <T> TinvokeAny(Collection<? extends Callable<T>> tasks) <T> TinvokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) Future<?><T> Future<T><T> Future<T>toString()Methods inherited from class org.apache.hadoop.thirdparty.com.google.common.util.concurrent.ForwardingExecutorService
awaitTermination, isShutdown, isTerminated, shutdown, shutdownNow
-
Constructor Details
-
SemaphoredDelegatingExecutor
public SemaphoredDelegatingExecutor(ExecutorService executorDelegatee, int permitCount, boolean fair, DurationTrackerFactory trackerFactory) Instantiate.- Parameters:
executorDelegatee- Executor to delegate topermitCount- number of permits into the queue permittedfair- should the semaphore be "fair"trackerFactory- duration tracker factory.
-
SemaphoredDelegatingExecutor
public SemaphoredDelegatingExecutor(ExecutorService executorDelegatee, int permitCount, boolean fair) Instantiate without collecting executor aquisition duration information.- Parameters:
executorDelegatee- Executor to delegate topermitCount- number of permits into the queue permittedfair- should the semaphore be "fair"
-
-
Method Details
-
delegate
- Specified by:
delegatein classorg.apache.hadoop.thirdparty.com.google.common.util.concurrent.ForwardingExecutorService
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks) throws InterruptedException - Specified by:
invokeAllin interfaceExecutorService- Overrides:
invokeAllin classorg.apache.hadoop.thirdparty.com.google.common.util.concurrent.ForwardingExecutorService- Throws:
InterruptedException
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException - Specified by:
invokeAllin interfaceExecutorService- Overrides:
invokeAllin classorg.apache.hadoop.thirdparty.com.google.common.util.concurrent.ForwardingExecutorService- Throws:
InterruptedException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException - Specified by:
invokeAnyin interfaceExecutorService- Overrides:
invokeAnyin classorg.apache.hadoop.thirdparty.com.google.common.util.concurrent.ForwardingExecutorService- Throws:
InterruptedExceptionExecutionException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
invokeAnyin interfaceExecutorService- Overrides:
invokeAnyin classorg.apache.hadoop.thirdparty.com.google.common.util.concurrent.ForwardingExecutorService- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
submit
- Specified by:
submitin interfaceExecutorService- Overrides:
submitin classorg.apache.hadoop.thirdparty.com.google.common.util.concurrent.ForwardingExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService- Overrides:
submitin classorg.apache.hadoop.thirdparty.com.google.common.util.concurrent.ForwardingExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService- Overrides:
submitin classorg.apache.hadoop.thirdparty.com.google.common.util.concurrent.ForwardingExecutorService
-
execute
-
getAvailablePermits
public int getAvailablePermits()Get the number of permits available; guaranteed to be0 <= availablePermits <= size.- Returns:
- the number of permits available at the time of invocation.
-
getWaitingCount
public int getWaitingCount()Get the number of threads waiting to acquire a permit.- Returns:
- snapshot of the length of the queue of blocked threads.
-
getPermitCount
public int getPermitCount()Total number of permits.- Returns:
- the number of permits as set in the constructor
-
toString
- Overrides:
toStringin classorg.apache.hadoop.thirdparty.com.google.common.collect.ForwardingObject
-