IScheduledExecutorService 介面
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
, ExecutorService
可將命令排程在指定的延遲之後執行,或定期執行。
[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
- 衍生
- 屬性
- 實作
備註
, ExecutorService
可將命令排程在指定的延遲之後執行,或定期執行。
方法 schedule
會建立具有各種延遲的工作,並傳回可用來取消或檢查執行的工作物件。 scheduleAtFixedRate
和 scheduleWithFixedDelay
方法會建立和執行定期執行的工作,直到取消為止。
使用 Executor#execute(Runnable)
和 ExecutorService
submit
方法提交的命令會排程為零的要求延遲。 方法中也允許 schedule
零和負延遲 (,但不允許期間) ,並視為立即執行的要求。
所有 schedule
方法都會接受 < em > 相對 < /em > 延遲和句點作為引數,而不是絕對時間或日期。 轉換以 java.util.Date
所需表單表示的絕對時間很簡單。 例如,若要在特定未來 date
排程,您可以使用: schedule(task, date.getTime() - System.currentTimeMillis(), TimeUnit.MILLISECONDS)
。 不過,請注意,由於網路時間同步處理通訊協定、時鐘漂移或其他因素,所以相對延遲的到期時間與啟用工作的目前 Date
時間不一致。
類別 Executors
會針對此套件中提供的 ScheduledExecutorService 實作提供方便的 Factory 方法。
<h2 > 使用範例 < /h2>
以下是一個類別,其方法會設定 ScheduledExecutorService,以每隔 10 秒進行一小時:
{@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);
}
}}
在 1.5 中新增。
的 java.util.concurrent.ScheduledExecutorService
JAVA 檔。
此頁面的部分是根據 原始碼專案所建立和共用的工作進行修改,並根據中所述的詞彙使用。
屬性
Handle |
取得基礎 Android 物件的 JNI 值。 (繼承來源 IJavaObject) |
IsShutdown |
如果此執行程式已經關閉,則傳 |
IsTerminated |
如果所有工作在關閉之後都已完成,則傳 |
JniIdentityHashCode |
傳回包裝實例的 |
JniManagedPeerState |
受控對等的狀態。 (繼承來源 IJavaPeerable) |
JniPeerMembers |
成員存取和調用支援。 (繼承來源 IJavaPeerable) |
PeerReference |
傳 JniObjectReference 回已包裝 JAVA 物件實例的 。 (繼承來源 IJavaPeerable) |
方法
AwaitTermination(Int64, TimeUnit) |
封鎖直到所有工作在關機要求之後完成執行,或發生逾時,或目前線程中斷,無論第一次發生。 (繼承來源 IExecutorService) |
Disposed() |
在處置實例時呼叫。 (繼承來源 IJavaPeerable) |
DisposeUnlessReferenced() |
如果沒有這個實例的未完成參考,則呼叫 |
Execute(IRunnable) |
在未來一段時間執行指定的命令。 (繼承來源 IExecutor) |
Finalized() |
實例完成時呼叫。 (繼承來源 IJavaPeerable) |
InvokeAll(ICollection) |
執行指定的工作,並在所有完成時傳回保留其狀態和結果的 Futures 清單。 (繼承來源 IExecutorService) |
InvokeAll(ICollection, Int64, TimeUnit) |
執行指定的工作,傳回所有完成或逾時到期時,保留其狀態和結果的 Futures 清單,無論第一次發生。 (繼承來源 IExecutorService) |
InvokeAny(ICollection) |
執行指定的工作,傳回已成功完成 (i 的結果。 (繼承來源 IExecutorService) |
InvokeAny(ICollection, Int64, TimeUnit) |
執行指定的工作,傳回已成功完成 (i 的結果。 (繼承來源 IExecutorService) |
Schedule(ICallable, Int64, TimeUnit) |
提交值傳回單次工作,該工作會在指定的延遲之後啟用。 |
Schedule(IRunnable, Int64, TimeUnit) |
提交在指定延遲之後啟用的單次工作。 |
ScheduleAtFixedRate(IRunnable, Int64, Int64, TimeUnit) |
提交一個定期動作,該動作會在指定的初始延遲之後先啟用,之後再提交指定的期間;也就是說,執行會在 之後開始 |
ScheduleWithFixedDelay(IRunnable, Int64, Int64, TimeUnit) |
提交在指定初始延遲之後第一次啟用的定期動作,並在終止一次執行和下一個執行開始之間加上指定的延遲。 |
SetJniIdentityHashCode(Int32) |
設定 所 |
SetJniManagedPeerState(JniManagedPeerStates) |
, |
SetPeerReference(JniObjectReference) |
設定 所 |
Shutdown() |
起始已執行先前提交工作的依序關機,但不會接受任何新工作。 (繼承來源 IExecutorService) |
ShutdownNow() |
嘗試停止所有主動執行的工作、停止等候工作的處理,並傳回等候執行的工作清單。 (繼承來源 IExecutorService) |
Submit(ICallable) |
提交值傳回工作以供執行,並傳回代表工作暫止結果的 Future。 (繼承來源 IExecutorService) |
Submit(IRunnable) |
提交可執行檔工作以供執行,並傳回代表該任務的未來。 (繼承來源 IExecutorService) |
Submit(IRunnable, Object) |
提交可執行檔工作以供執行,並傳回代表該任務的未來。 (繼承來源 IExecutorService) |
UnregisterFromRuntime() |
取消註冊此實例,讓執行時間不會從未來的 Java.Interop.JniRuntime+JniValueManager.PeekValue 調用傳回它。 (繼承來源 IJavaPeerable) |
擴充方法
JavaCast<TResult>(IJavaObject) |
執行 Android 執行時間檢查的類型轉換。 |
JavaCast<TResult>(IJavaObject) |
, |
GetJniTypeName(IJavaPeerable) |
, |
AwaitTerminationAsync(IExecutorService, Int64, TimeUnit) |
, |
InvokeAnyAsync(IExecutorService, ICollection) |
, |
InvokeAnyAsync(IExecutorService, ICollection, Int64, TimeUnit) |
, |