Future instances. Note
that, whenever possible, it is strongly preferred to modify those libraries to return ListenableFuture directly.
For interoperability between ListenableFuture and CompletableFuture,
consider Future Converter.
Futures.makeListenable, which existed in 1.0)
| Modifier and Type | Class and Description |
|---|---|
| private static class | JdkFutureAdapters.
An adapter to turn a |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static <V extends @Nullable Object> ListenableFuture | listenInPoolThread(Future<V> future)
Assigns a thread to the given |
| public static <V extends @Nullable Object> ListenableFuture | listenInPoolThread(Future<V> future, Executor executor)
Submits a blocking task for the given |
| JdkFutureAdapters | back to summary |
|---|---|
| private JdkFutureAdapters() | |
| listenInPoolThread | back to summary |
|---|---|
| public static <V extends @Nullable Object> ListenableFuture Assigns a thread to the given Warning If the input future does not already implement Prefer to create | |
| listenInPoolThread | back to summary |
|---|---|
| public static <V extends @Nullable Object> ListenableFuture Submits a blocking task for the given Warning If the input future does not already implement Prefer to create
| |
Future into a ListenableFuture. This will wait on the
future to finish, and when it completes, run the listeners. This implementation will wait on
the source future indefinitely, so if the source future never completes, the adapter will never
complete either.
If the delegate future is interrupted or throws an unexpected unchecked exception, the listeners will not be invoked.
| Modifier and Type | Field and Description |
|---|---|
| private final Executor | |
| private static final Executor | |
| private final Future | |
| private final ExecutionList | |
| private final AtomicBoolean | |
| private static final ThreadFactory |
| Access | Constructor and Description |
|---|---|
| pack-priv | |
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | addListener(Runnable
the listener to run when the computation is complete listener, Executor the executor to run the listener in exec)Implements com. |
| protected Future | delegate()
Implements abstract com. |
| adapterExecutor | back to summary |
|---|---|
| private final Executor adapterExecutor | |
| defaultAdapterExecutor | back to summary |
|---|---|
| private static final Executor defaultAdapterExecutor | |
| delegate | back to summary |
|---|---|
| private final Future<V> delegate | |
| executionList | back to summary |
|---|---|
| private final ExecutionList executionList | |
| hasListeners | back to summary |
|---|---|
| private final AtomicBoolean hasListeners | |
| threadFactory | back to summary |
|---|---|
| private static final ThreadFactory threadFactory | |
| ListenableFutureAdapter | back to summary |
|---|---|
| pack-priv ListenableFutureAdapter(Future<V> delegate) | |
| ListenableFutureAdapter | back to summary |
|---|---|
| pack-priv ListenableFutureAdapter(Future<V> delegate, Executor adapterExecutor) | |
| addListener | back to summary |
|---|---|
| public void addListener(Runnable listener, Executor exec) Implements com. Doc from com. Registers a listener to be run on the given executor.
The listener will run when the There is no guaranteed ordering of execution of listeners, but any listener added through this method is guaranteed to be called once the computation is complete. Exceptions thrown by a listener will be propagated up to the executor. Any exception thrown
during Note If your listener is lightweight -- and will not cause stack overflow by completing
more futures or adding more This is the most general listener interface. For common operations performed using
listeners, see Memory consistency effects: Actions in a thread prior to adding a listener happen-before its execution begins, perhaps in another thread. Guava implementations of | |
| delegate | back to summary |
|---|---|
| protected Future Implements abstract com. Doc from com. Returns the backing delegate instance that methods are forwarded to. Abstract subclasses
generally override this method with an abstract method that has a more specific return type,
such as
| |