ThreadPoolExecutor.AfterExecute(IRunnable, Throwable) Method

Definition

Method invoked upon completion of execution of the given Runnable.

[Android.Runtime.Register("afterExecute", "(Ljava/lang/Runnable;Ljava/lang/Throwable;)V", "GetAfterExecute_Ljava_lang_Runnable_Ljava_lang_Throwable_Handler")]
protected virtual void AfterExecute (Java.Lang.IRunnable? r, Java.Lang.Throwable? t);
[<Android.Runtime.Register("afterExecute", "(Ljava/lang/Runnable;Ljava/lang/Throwable;)V", "GetAfterExecute_Ljava_lang_Runnable_Ljava_lang_Throwable_Handler")>]
abstract member AfterExecute : Java.Lang.IRunnable * Java.Lang.Throwable -> unit
override this.AfterExecute : Java.Lang.IRunnable * Java.Lang.Throwable -> unit

Parameters

r
IRunnable

the runnable that has completed

t
Throwable

the exception that caused termination, or null if execution completed normally

Attributes

Remarks

Method invoked upon completion of execution of the given Runnable. This method is invoked by the thread that executed the task. If non-null, the Throwable is the uncaught RuntimeException or Error that caused execution to terminate abruptly.

This implementation does nothing, but may be customized in subclasses. Note: To properly nest multiple overridings, subclasses should generally invoke super.afterExecute at the beginning of this method.

<b>Note:</b> When actions are enclosed in tasks (such as FutureTask) either explicitly or via methods such as submit, these task objects catch and maintain computational exceptions, and so they do not cause abrupt termination, and the internal exceptions are <em>not</em> passed to this method. If you would like to trap both kinds of failures in this method, you can further probe for such cases, as in this sample subclass that prints either the direct cause or the underlying exception if a task has been aborted:

{@code
            class ExtendedExecutor extends ThreadPoolExecutor {
              // ...
              protected void afterExecute(Runnable r, Throwable t) {
                super.afterExecute(r, t);
                if (t == null
                    && r instanceof Future<?>
                    && ((Future<?>)r).isDone()) {
                  try {
                    Object result = ((Future<?>) r).get();
                  } catch (CancellationException ce) {
                    t = ce;
                  } catch (ExecutionException ee) {
                    t = ee.getCause();
                  } catch (InterruptedException ie) {
                    // ignore/reset
                    Thread.currentThread().interrupt();
                  }
                }
                if (t != null)
                  System.out.println(t);
              }
            }}

Java documentation for java.util.concurrent.ThreadPoolExecutor.afterExecute(java.lang.Runnable, java.lang.Throwable).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to