IExecutor Interface

Definition

An object that executes submitted Runnable tasks.

[Android.Runtime.Register("java/util/concurrent/Executor", "", "Java.Util.Concurrent.IExecutorInvoker")]
public interface IExecutor : Android.Runtime.IJavaObject, IDisposable, Java.Interop.IJavaPeerable
[<Android.Runtime.Register("java/util/concurrent/Executor", "", "Java.Util.Concurrent.IExecutorInvoker")>]
type IExecutor = interface
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Derived
Attributes
Implements

Remarks

An object that executes submitted Runnable tasks. This interface provides a way of decoupling task submission from the mechanics of how each task will be run, including details of thread use, scheduling, etc. An Executor is normally used instead of explicitly creating threads. For example, rather than invoking new Thread(new RunnableTask()).start() for each of a set of tasks, you might use:

{@code
            Executor executor = anExecutor();
            executor.execute(new RunnableTask1());
            executor.execute(new RunnableTask2());
            ...}

However, the Executor interface does not strictly require that execution be asynchronous. In the simplest case, an executor can run the submitted task immediately in the caller's thread:

{@code
            class DirectExecutor implements Executor {
              public void execute(Runnable r) {
                r.run();
              }
            }}

More typically, tasks are executed in some thread other than the caller's thread. The executor below spawns a new thread for each task.

{@code
            class ThreadPerTaskExecutor implements Executor {
              public void execute(Runnable r) {
                new Thread(r).start();
              }
            }}

Many Executor implementations impose some sort of limitation on how and when tasks are scheduled. The executor below serializes the submission of tasks to a second executor, illustrating a composite executor.

{@code
            class SerialExecutor implements Executor {
              final Queue<Runnable> tasks = new ArrayDeque<>();
              final Executor executor;
              Runnable active;

              SerialExecutor(Executor executor) {
                this.executor = executor;
              }

              public synchronized void execute(Runnable r) {
                tasks.add(() -> {
                  try {
                    r.run();
                  } finally {
                    scheduleNext();
                  }
                });
                if (active == null) {
                  scheduleNext();
                }
              }

              protected synchronized void scheduleNext() {
                if ((active = tasks.poll()) != null) {
                  executor.execute(active);
                }
              }
            }}

The Executor implementations provided in this package implement ExecutorService, which is a more extensive interface. The ThreadPoolExecutor class provides an extensible thread pool implementation. The Executors class provides convenient factory methods for these Executors.

Memory consistency effects: Actions in a thread prior to submitting a Runnable object to an Executor<i>happen-before</i> its execution begins, perhaps in another thread.

Added in 1.5.

Java documentation for java.util.concurrent.Executor.

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.

Properties

Handle

Gets the JNI value of the underlying Android object.

(Inherited from IJavaObject)
JniIdentityHashCode

Returns the value of java.lang.System.identityHashCode() for the wrapped instance.

(Inherited from IJavaPeerable)
JniManagedPeerState

State of the managed peer.

(Inherited from IJavaPeerable)
JniPeerMembers

Member access and invocation support.

(Inherited from IJavaPeerable)
PeerReference

Returns a JniObjectReference of the wrapped Java object instance.

(Inherited from IJavaPeerable)

Methods

Disposed()

Called when the instance has been disposed.

(Inherited from IJavaPeerable)
DisposeUnlessReferenced()

If there are no outstanding references to this instance, then calls Dispose(); otherwise, does nothing.

(Inherited from IJavaPeerable)
Execute(IRunnable)

Executes the given command at some time in the future.

Finalized()

Called when the instance has been finalized.

(Inherited from IJavaPeerable)
SetJniIdentityHashCode(Int32)

Set the value returned by JniIdentityHashCode.

(Inherited from IJavaPeerable)
SetJniManagedPeerState(JniManagedPeerStates) (Inherited from IJavaPeerable)
SetPeerReference(JniObjectReference)

Set the value returned by PeerReference.

(Inherited from IJavaPeerable)
UnregisterFromRuntime()

Unregister this instance so that the runtime will not return it from future Java.Interop.JniRuntime+JniValueManager.PeekValue invocations.

(Inherited from IJavaPeerable)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to