Class ExecutionList
- java.lang.Object
-
- com.google.common.util.concurrent.ExecutionList
-
@GwtIncompatible public final class ExecutionList extends java.lang.Object
A support class forListenableFutureimplementations to manage their listeners. An instance contains a list of listeners, each with an associatedExecutor, and guarantees that everyRunnablethat is added will be executed afterexecute()is called. AnyRunnableadded after the call toexecuteis still guaranteed to execute. There is no guarantee, however, that listeners will be executed in the order that they are added.Exceptions thrown by a listener will be propagated up to the executor. Any exception thrown during
Executor.execute(e.g., aRejectedExecutionExceptionor an exception thrown by direct execution) will be caught and logged.- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classExecutionList.RunnableExecutorPair
-
Field Summary
Fields Modifier and Type Field Description private booleanexecutedprivate static java.util.logging.LoggerlogLogger to log exceptions caught when running runnables.private ExecutionList.RunnableExecutorPairrunnablesThe runnable, executor pairs to execute.
-
Constructor Summary
Constructors Constructor Description ExecutionList()Creates a new, emptyExecutionList.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.lang.Runnable runnable, java.util.concurrent.Executor executor)Adds theRunnableand accompanyingExecutorto the list of listeners to execute.voidexecute()Runs this execution list, executing all existing pairs in the order they were added.private static voidexecuteListener(java.lang.Runnable runnable, java.util.concurrent.Executor executor)Submits the given runnable to the givenExecutorcatching and logging all runtime exceptions thrown by the executor.
-
-
-
Field Detail
-
log
private static final java.util.logging.Logger log
Logger to log exceptions caught when running runnables.
-
runnables
private ExecutionList.RunnableExecutorPair runnables
The runnable, executor pairs to execute. This acts as a stack threaded through theExecutionList.RunnableExecutorPair.nextfield.
-
executed
private boolean executed
-
-
Constructor Detail
-
ExecutionList
public ExecutionList()
Creates a new, emptyExecutionList.
-
-
Method Detail
-
add
public void add(java.lang.Runnable runnable, java.util.concurrent.Executor executor)Adds theRunnableand accompanyingExecutorto the list of listeners to execute. If execution has already begun, the listener is executed immediately.When selecting an executor, note that
directExecutoris dangerous in some cases. See the discussion in theListenableFuture.addListenerdocumentation.
-
execute
public void execute()
Runs this execution list, executing all existing pairs in the order they were added. However, note that listeners added after this point may be executed before those previously added, and note that the execution order of all listeners is ultimately chosen by the implementations of the supplied executors.This method is idempotent. Calling it several times in parallel is semantically equivalent to calling it exactly once.
- Since:
- 10.0 (present in 1.0 as
run)
-
executeListener
private static void executeListener(java.lang.Runnable runnable, java.util.concurrent.Executor executor)Submits the given runnable to the givenExecutorcatching and logging all runtime exceptions thrown by the executor.
-
-