Package com.palantir.common.concurrent
Class MultiplexingCompletionService<K,V>
- java.lang.Object
-
- com.palantir.common.concurrent.MultiplexingCompletionService<K,V>
-
- Type Parameters:
K
- key typeV
- return type of tasks that are to be submitted
public final class MultiplexingCompletionService<K,V> extends Object
A MultiplexingCompletionService is much like aExecutorCompletionService
, but supports multiple delegateExecutorService
s feeding in to a single sharedBlockingQueue
.poll()
operations will retrieve the results of computations that are done first (regardless of which actual underlying executor service they may have been scheduled on). Maintaining separate executors may see application in improving monitoring and bounding of thread pools that have several distinct use cases.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <K,V>
MultiplexingCompletionService<K,V>create(Map<? extends K,ExecutorService> executors)
static <K,V>
MultiplexingCompletionService<K,V>createFromCheckedExecutors(Map<? extends K,CheckedRejectionExecutorService> executors)
Future<Map.Entry<K,V>>
poll()
Future<Map.Entry<K,V>>
poll(long timeout, TimeUnit unit)
Future<Map.Entry<K,V>>
submit(K key, Callable<V> task)
Submits a task to be run on a specific executor.
-
-
-
Method Detail
-
create
public static <K,V> MultiplexingCompletionService<K,V> create(Map<? extends K,ExecutorService> executors)
-
createFromCheckedExecutors
public static <K,V> MultiplexingCompletionService<K,V> createFromCheckedExecutors(Map<? extends K,CheckedRejectionExecutorService> executors)
-
submit
public Future<Map.Entry<K,V>> submit(K key, Callable<V> task) throws CheckedRejectedExecutionException
Submits a task to be run on a specific executor.- Parameters:
key
- to identify which executor the task should be run ontask
- to be run on the relevant executor- Returns:
- future associated with submitting the task to the correct executor
- Throws:
IllegalStateException
- if the key provided is not associated with any executorCheckedRejectedExecutionException
- if the task could not be submitted to the relevant executor
-
poll
public Future<Map.Entry<K,V>> poll(long timeout, TimeUnit unit) throws InterruptedException
- Throws:
InterruptedException
-
-