|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
前のクラス 次のクラス | フレームあり フレームなし | |||||||||
概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド |
public interface ScheduledExecutorService
指定された遅延時間後、または周期的にコマンドの実行をスケジュール可能な ExecutorService
。
schedule メソッドは、さまざまな遅延を持つタスクを作成し、実行の取り消しやチェックに使用可能なタスクオブジェクトを返します。scheduleAtFixedRate および scheduleWithFixedDelay メソッドは、取り消されるまで周期的に実行されるタスクを作成および実行します。
Executor.execute(java.lang.Runnable)
および ExecutorService
submit メソッドを使用して送信されるコマンドは、要求された遅延ゼロでスケジューリングされます。値がゼロおよび負の遅延 (ピリオドはなし) も schedule メソッドで許可および処理され、ただちに実行されます。
すべての schedule メソッドは、引数として、絶対時間や日付ではなく「相対的な」遅延および期間を受け入れます。Date
で表される絶対時間を要求された形式に変換するのは簡単です。たとえば、将来の特定の date にスケジュールを設定する場合は、schedule(task, date.getTime() - System.currentTimeMillis(), TimeUnit.MILLISECONDS) を使用できます。ただし、相対遅延の有効期限が現在の Date (この時点で、ネットワーク時刻同期プロトコル、クロックずれ、または他の要因のためにタスクが有効になる) に一致する必要はないことに留意してください。
Executors
クラスは、このパッケージで提供される ScheduledExecutorService 実装用の利便性の高いファクトリメソッドを提供します。
import static java.util.concurrent.TimeUnit.*; class BeeperControl { private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); public void beepForAnHour() { final Runnable beeper = new Runnable() { public void run() { System.out.println("beep"); } }; final ScheduledFuture<?> beeperHandle = scheduler.scheduleAtFixedRate(beeper, 10, 10, SECONDS); scheduler.schedule(new Runnable() { public void run() { beeperHandle.cancel(true); } }, 60 * 60, SECONDS); } }
メソッドの概要 | ||
---|---|---|
|
schedule(Callable<V> callable,
long delay,
TimeUnit unit)
指定された遅延後に有効になる ScheduledFuture を作成および実行します。 |
|
ScheduledFuture<?> |
schedule(Runnable command,
long delay,
TimeUnit unit)
指定された遅延後に有効になる単発的なアクションを作成および実行します。 |
|
ScheduledFuture<?> |
scheduleAtFixedRate(Runnable command,
long initialDelay,
long period,
TimeUnit unit)
指定された初期遅延後に最初に有効になり、以降は指定された期間後に有効になる周期的なアクションを作成および実行します。 |
|
ScheduledFuture<?> |
scheduleWithFixedDelay(Runnable command,
long initialDelay,
long delay,
TimeUnit unit)
指定された初期遅延後に最初に有効になり、以降は実行終了から次の実行開始までの指定遅延後に有効になる周期的なアクションを作成および実行します。 |
インタフェース java.util.concurrent.ExecutorService から継承されたメソッド |
---|
awaitTermination, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow, submit, submit, submit |
インタフェース java.util.concurrent.Executor から継承されたメソッド |
---|
execute |
メソッドの詳細 |
---|
ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
command
- 実行するタスクdelay
- 現在からの実行遅延時間unit
- 遅延パラメータの時間単位
RejectedExecutionException
- タスクの実行をスケジュールできない場合
NullPointerException
- コマンドが null の場合<V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit)
callable
- 実行する関数delay
- 現在からの実行遅延時間unit
- 遅延パラメータの時間単位
RejectedExecutionException
- タスクの実行をスケジュールできない場合
NullPointerException
- callable が null の場合ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
command
- 実行するタスクinitialDelay
- 最初の実行の遅延時間period
- 後続の実行間隔unit
- initialDelay および period パラメータの時間単位
RejectedExecutionException
- タスクの実行をスケジュールできない場合
NullPointerException
- コマンドが null の場合
IllegalArgumentException
- 期間がゼロ以下の場合ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
command
- 実行するタスクinitialDelay
- 最初の実行の遅延時間delay
- 実行終了から次の実行開始までの遅延unit
- initialDelay および delay パラメータの時間単位
RejectedExecutionException
- タスクの実行をスケジュールできない場合
NullPointerException
- コマンドが null の場合
IllegalArgumentException
- 遅延がゼロ以下の場合
|
JavaTM 2 Platform Standard Ed. 5.0 |
|||||||||
前のクラス 次のクラス | フレームあり フレームなし | |||||||||
概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド |
Copyright 2004 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Documentation Redistribution Policy も参照してください。