Condividi tramite


IScheduledExecutorService Interface

Definition

An ExecutorService that can schedule commands to run after a given delay, or to execute periodically.

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

Remarks

An ExecutorService that can schedule commands to run after a given delay, or to execute periodically.

The schedule methods create tasks with various delays and return a task object that can be used to cancel or check execution. The scheduleAtFixedRate and scheduleWithFixedDelay methods create and execute tasks that run periodically until cancelled.

Commands submitted using the Executor#execute(Runnable) and ExecutorServicesubmit methods are scheduled with a requested delay of zero. Zero and negative delays (but not periods) are also allowed in schedule methods, and are treated as requests for immediate execution.

All schedule methods accept <em>relative</em> delays and periods as arguments, not absolute times or dates. It is a simple matter to transform an absolute time represented as a java.util.Date to the required form. For example, to schedule at a certain future date, you can use: schedule(task, date.getTime() - System.currentTimeMillis(), TimeUnit.MILLISECONDS). Beware however that expiration of a relative delay need not coincide with the current Date at which the task is enabled due to network time synchronization protocols, clock drift, or other factors.

The Executors class provides convenient factory methods for the ScheduledExecutorService implementations provided in this package.

<h2>Usage Example</h2>

Here is a class with a method that sets up a ScheduledExecutorService to beep every ten seconds for an hour:

{@code
            import static java.util.concurrent.TimeUnit.*;
            class BeeperControl {
              private final ScheduledExecutorService scheduler =
                Executors.newScheduledThreadPool(1);

              public void beepForAnHour() {
                Runnable beeper = () -> System.out.println("beep");
                ScheduledFuture<?> beeperHandle =
                  scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS);
                Runnable canceller = () -> beeperHandle.cancel(false);
                scheduler.schedule(canceller, 1, HOURS);
              }
            }}

Added in 1.5.

Java documentation for java.util.concurrent.ScheduledExecutorService.

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)
IsShutdown

Returns true if this executor has been shut down.

(Inherited from IExecutorService)
IsTerminated

Returns true if all tasks have completed following shut down.

(Inherited from IExecutorService)
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

AwaitTermination(Int64, TimeUnit)

Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.

(Inherited from IExecutorService)
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.

(Inherited from IExecutor)
Finalized()

Called when the instance has been finalized.

(Inherited from IJavaPeerable)
InvokeAll(ICollection, Int64, TimeUnit)

Executes the given tasks, returning a list of Futures holding their status and results when all complete or the timeout expires, whichever happens first.

(Inherited from IExecutorService)
InvokeAll(ICollection)

Executes the given tasks, returning a list of Futures holding their status and results when all complete.

(Inherited from IExecutorService)
InvokeAny(ICollection, Int64, TimeUnit)

Executes the given tasks, returning the result of one that has completed successfully (i.

(Inherited from IExecutorService)
InvokeAny(ICollection)

Executes the given tasks, returning the result of one that has completed successfully (i.

(Inherited from IExecutorService)
Schedule(ICallable, Int64, TimeUnit)

Submits a value-returning one-shot task that becomes enabled after the given delay.

Schedule(IRunnable, Int64, TimeUnit)

Submits a one-shot task that becomes enabled after the given delay.

ScheduleAtFixedRate(IRunnable, Int64, Int64, TimeUnit)

Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is, executions will commence after initialDelay, then initialDelay + period, then initialDelay + 2 * period, and so on.

ScheduleWithFixedDelay(IRunnable, Int64, Int64, TimeUnit)

Submits a periodic action that becomes enabled first after the given initial delay, and subsequently with the given delay between the termination of one execution and the commencement of the next.

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)
Shutdown()

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.

(Inherited from IExecutorService)
ShutdownNow()

Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.

(Inherited from IExecutorService)
Submit(ICallable)

Submits a value-returning task for execution and returns a Future representing the pending results of the task.

(Inherited from IExecutorService)
Submit(IRunnable, Object)

Submits a Runnable task for execution and returns a Future representing that task.

(Inherited from IExecutorService)
Submit(IRunnable)

Submits a Runnable task for execution and returns a Future representing that task.

(Inherited from IExecutorService)
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)
AwaitTerminationAsync(IExecutorService, Int64, TimeUnit)
InvokeAnyAsync(IExecutorService, ICollection, Int64, TimeUnit)
InvokeAnyAsync(IExecutorService, ICollection)

Applies to