@ThreadSafe public final class AsyncCompleter extends Object
CompletionService
usage that allows a collection of jobs to be issued to an
Executor and return an
Iterable of the results that is in the order that the
results return.
Unlike
ExecutorService.invokeAll(java.util.Collection)
invokeAll(Iterable) here does not itself block, rather the
Iterator.next() calls to the returned
Iterable will block the first time it is iterated. This
allows the client to defer the reification of the result until it is ready to
use it.
To create an instance of this class, please use the supplied
AsyncCompleter.Builder.
| Modifier and Type | Class and Description |
|---|---|
static class |
AsyncCompleter.Builder
For creating instances of
AsyncCompleter. |
static interface |
AsyncCompleter.ExecutorCompletionServiceFactory
Extension point if a custom CompletionService is required, for instance to
implement a custom concellation policy.
|
| Modifier and Type | Method and Description |
|---|---|
<T> Iterable<T> |
invokeAll(Iterable<? extends Callable<T>> callables)
|
<T> Iterable<T> |
invokeAll(Iterable<? extends Callable<T>> callables,
long time,
TimeUnit unit)
Version of
invokeAll(Iterable) that supports a timeout. |
public <T> Iterable<T> invokeAll(Iterable<? extends Callable<T>> callables)
jobs on the contained
Executor and return a lazily evaluated
Iterable of the results in the order they return in
(fastest first).
Note that if any of the jobs return null then nulls WILL BE included in the
results. Similarly if an exception is thrown and exceptions are being
ignored then there will be a NULL result returned. If you want to filter
nulls this is trivial, but be aware that filtering of the results forces
Iterator.next() to be called while calling
Iterator.hasNext() (which may block).
T - the result typecallables - the jobs to runpublic <T> Iterable<T> invokeAll(Iterable<? extends Callable<T>> callables, long time, TimeUnit unit)
invokeAll(Iterable) that supports a timeout. Any jobs
that are not complete by the timeout are interrupted and discarded.T - the result typecallables - the jobs to runtime - the max time spent per job specified by:unit - the TimeUnit time is specified ininvokeAll(Iterable)Copyright © 2016 Atlassian. All rights reserved.