FutureTask that also implements the ListenableFuture interface. Unlike FutureTask, ListenableFutureTask does not provide an overrideable done() method. For similar functionality, call addListener.
Few users should use this class. It is intended primarily for those who are implementing an
ExecutorService. Most users should call ListeningExecutorService. on a service obtained from MoreExecutors#listeningDecorator.
| Modifier and Type | Field and Description |
|---|---|
| private final ExecutionList |
| 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. |
| public static <V extends @Nullable Object> ListenableFutureTask | |
| public static <V extends @Nullable Object> ListenableFutureTask | create(Runnable
the runnable task runnable, V the result to return on successful completion. If you don't need a particular
result, consider using constructions of the form: result)ListenableFuture<?> f =
ListenableFutureTask.create(runnable, null)Creates a |
| protected void | done()
Overrides java. |
| public V | get(long
the maximum time to wait timeout, TimeUnit the time unit of the timeout argument unit)Overrides java. Implements java. |
| executionList | back to summary |
|---|---|
| private final ExecutionList executionList | |
| ListenableFutureTask | back to summary |
|---|---|
| pack-priv ListenableFutureTask(Callable<V> callable) | |
| ListenableFutureTask | back to summary |
|---|---|
| pack-priv ListenableFutureTask(Runnable runnable, V result) | |
| 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 | |
| create | back to summary |
|---|---|
| public static <V extends @Nullable Object> ListenableFutureTask Creates a
| |
| create | back to summary |
|---|---|
| public static <V extends @Nullable Object> ListenableFutureTask Creates a
| |
| done | back to summary |
|---|---|
| protected void done() Overrides java. Internal implementation detail used to invoke the listeners.
| |
| get | back to summary |
|---|---|
| public V get(long timeout, TimeUnit unit) throws TimeoutException, InterruptedException, ExecutionException Overrides java. Implements java. Doc from java. Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.
| |