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 {@code Executor.execute} (e.g., a {@code RejectedExecutionException} or an exception thrown by {@linkplain MoreExecutors#directExecutor direct execution}) will be caught and logged.
Note: For fast, lightweight listeners that would be safe to execute in any thread, consider {@link MoreExecutors#directExecutor}. For heavier listeners, {@code directExecutor()} carries some caveats. Forexample, the listener may run on an unpredictable or undesirable thread:
Also note that, regardless of which thread executes the {@code directExecutor()} listener, all other registered but unexecutedlisteners are prevented from running during its execution, even if those listeners are to run in other executors.
This is the most general listener interface. For common operations performed using listeners, see {@link com.google_voltpatches.common.util.concurrent.Futures}. For a simplified but general listener interface, see {@link com.google_voltpatches.common.util.concurrent.Futures#addCallback addCallback()}. @param listener the listener to run when the computation is complete @param executor the executor to run the listener in @throws NullPointerException if the executor or listener was null @throws RejectedExecutionException if we tried to execute the listenerimmediately but the executor rejected it.
|
|