public final class ExecutionList
extends java.lang.Object
ListenableFuture implementations to manage their listeners. An
instance contains a list of listeners, each with an associated Executor, and guarantees
that every Runnable that is added will be executed after execute() is called. Any Runnable added after the call to execute is 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., a RejectedExecutionException or an exception
thrown by direct execution) will be caught and logged.
| Modifier and Type | Class and Description |
|---|---|
private static class |
ExecutionList.RunnableExecutorPair |
| Modifier and Type | Field and Description |
|---|---|
private boolean |
executed |
private static java.util.logging.Logger |
log
Logger to log exceptions caught when running runnables.
|
private ExecutionList.RunnableExecutorPair |
runnables
The runnable, executor pairs to execute.
|
| Constructor and Description |
|---|
ExecutionList()
Creates a new, empty
ExecutionList. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(java.lang.Runnable runnable,
java.util.concurrent.Executor executor)
Adds the
Runnable and accompanying Executor to the list of listeners to
execute. |
void |
execute()
Runs this execution list, executing all existing pairs in the order they were added.
|
private static void |
executeListener(java.lang.Runnable runnable,
java.util.concurrent.Executor executor)
Submits the given runnable to the given
Executor catching and logging all runtime exceptions thrown by the executor. |
private static final java.util.logging.Logger log
@CheckForNull private ExecutionList.RunnableExecutorPair runnables
ExecutionList.RunnableExecutorPair.next field.private boolean executed
public ExecutionList()
ExecutionList.public void add(java.lang.Runnable runnable,
java.util.concurrent.Executor executor)
Runnable and accompanying Executor to the list of listeners to
execute. If execution has already begun, the listener is executed immediately.
When selecting an executor, note that directExecutor is dangerous in some cases. See
the discussion in the ListenableFuture.addListener
documentation.
public void execute()
This method is idempotent. Calling it several times in parallel is semantically equivalent to calling it exactly once.
run)private static void executeListener(java.lang.Runnable runnable,
java.util.concurrent.Executor executor)
Executor catching and logging all runtime exceptions thrown by the executor.