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#sameThreadExecutor inline execution}) will be caught and logged.
Note: For fast, lightweight listeners that would be safe to execute in any thread, consider {@link MoreExecutors#sameThreadExecutor}. For heavier listeners, {@code sameThreadExecutor()} carries some caveats: First, thethread that the listener runs in depends on whether the {@code Future} isdone at the time it is added. In particular, if added late, listeners will run in the thread that calls {@code addListener}. Second, listeners may run in an internal thread of the system responsible for the input {@code Future}, such as an RPC network thread. Finally, during the execution of a listener, the thread cannot submit any additional listeners for 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.common.util.concurrent.Futures} @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.
|
|