|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||
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 - delay パラメータの時間単位
RejectedExecutionException - タスクの実行をスケジュールできない場合
NullPointerException - コマンドが null の場合
<V> ScheduledFuture<V> schedule(Callable<V> callable,
long delay,
TimeUnit unit)
callable - 実行する関数delay - 現在から遅延実行までの時間unit - delay パラメータの時間単位
RejectedExecutionException - タスクの実行をスケジュールできない場合
NullPointerException - 呼び出し可能レイアウトが null の場合
ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
long initialDelay,
long period,
TimeUnit unit)
command - 実行するタスクinitialDelay - 最初の遅延実行までの時間period - 連続する実行の間隔unit - initialDelay および period パラメータの時間単位
RejectedExecutionException - タスクの実行をスケジュールできない場合
NullPointerException - コマンドが null の場合
IllegalArgumentException - period が 0 以下である場合
ScheduledFuture<?> scheduleWithFixedDelay(Runnable command,
long initialDelay,
long delay,
TimeUnit unit)
command - 実行するタスクinitialDelay - 最初の遅延実行までの時間delay - 実行の終了後から次の開始までの遅延unit - initialDelay および delay パラメータの時間単位
RejectedExecutionException - タスクの実行をスケジュールできない場合
NullPointerException - コマンドが null の場合
IllegalArgumentException - delay が 0 以下である場合
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | |||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | |||||||||
Copyright 2009 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Documentation Redistribution Policy も参照してください。