@Override public void addListener(final Runnable listener, final Executor executor) { // Wrap the listener Runnable in a DelegatingRunnable. If the specified executor is one that // runs tasks in the same thread as the caller submitting the task // (e.g. {@link com.google.common.util.concurrent.MoreExecutors#sameThreadExecutor}) and the // listener is executed from the #done method, then the DelegatingRunnable will detect this // via the ThreadLocal and submit the listener Runnable to the listenerExecutor. // // On the other hand, if this task is already complete, the call to ExecutionList#add in // superclass will execute the listener Runnable immediately and, since the ThreadLocal won't be set, // the DelegatingRunnable will run the listener Runnable inline. super.addListener(new DelegatingRunnable(listener, listenerExecutor), executor); } }
@Override public void addListener(final Runnable listener, final Executor executor) { // Wrap the listener Runnable in a DelegatingRunnable. If the specified executor is one that // runs tasks in the same thread as the caller submitting the task // (e.g. {@link com.google.common.util.concurrent.MoreExecutors#sameThreadExecutor}) and the // listener is executed from the #done method, then the DelegatingRunnable will detect this // via the ThreadLocal and submit the listener Runnable to the listenerExecutor. // // On the other hand, if this task is already complete, the call to ExecutionList#add in // superclass will execute the listener Runnable immediately and, since the ThreadLocal won't be set, // the DelegatingRunnable will run the listener Runnable inline. super.addListener(new DelegatingRunnable(listener, listenerExecutor), executor); } }