インターフェース Trigger
- すべての既知のサブインターフェース:
ZonedTrigger
- すべての既知の実装クラス:
CronTrigger
public interface Trigger
トリガーを使用すると、アプリケーション開発者は、タスクを実行するタイミングと頻度に関するルールをプラグインできます。トリガーは、単一の絶対日時のように単純にすることも、Jakarta™ EE ビジネスカレンダーロジックを含めることもできます。トリガーの実装は、アプリケーション開発者によって作成され(または、外部からアプリケーションに提供される場合があります)、いずれかのスケジュール方法を使用して
ManagedScheduledExecutorService に送信されると、タスクに登録されます。各メソッドは、不特定のコンテキストで実行されます。メソッドは、ContextService を使用してコンテキストプロキシオブジェクトを作成することでコンテキスト化できます。各トリガーインスタンスは、それが登録されたのと同じプロセス内で呼び出されます。
例:
/**
* A trigger that only returns a single date.
*/
public class SingleDateTrigger implements Trigger {
private Date fireTime;
public TriggerSingleDate(Date newDate) {
fireTime = newDate;
}
public Date getNextRunTime(
LastExecution lastExecutionInfo, Date taskScheduledTime) {
if(taskScheduledTime.after(fireTime)) {
return null;
}
return fireTime;
}
public boolean skipRun(LastExecution lastExecutionInfo, Date scheduledRunTime) {
return scheduledRunTime.after(fireTime);
}
}
/**
* A fixed-rate trigger that will skip any runs if
* the latencyAllowance threshold is exceeded (the task
* ran too late).
*/
public class TriggerFixedRateLatencySensitive implements Trigger {
private Date startTime;
private long delta;
private long latencyAllowance;
public TriggerFixedRateLatencySensitive(Date startTime, long delta, long latencyAllowance) {
this.startTime = startTime;
this.delta = delta;
this.latencyAllowance = latencyAllowance;
}
public Date getNextRunTime(LastExecution lastExecutionInfo,
Date taskScheduledTime) {
if(lastExecutionInfo==null) {
return startTime;
}
return new Date(lastExecutionInfo.getScheduledStart().getTime() + delta);
}
public boolean skipRun(LastExecution lastExecutionInfo, Date scheduledRunTime) {
return System.currentTimeMillis() - scheduledRunTime.getTime() > latencyAllowance;
}
}
- 導入:
- 1.0
方法の概要
修飾子と型メソッド説明getNextRunTime(LastExecution lastExecutionInfo, DateSE taskScheduledTime) 次回タスクを実行する時間を取得します。booleanskipRun(LastExecution lastExecutionInfo, DateSE scheduledRunTime) この実行インスタンスをスキップする必要がある場合は true を返します。
メソッドの詳細
getNextRunTime
次回タスクを実行する時間を取得します。- パラメーター:
lastExecutionInfo- タスクの最後の実行に関する情報。タスクがまだ実行されていない場合、この値は null になります。taskScheduledTime- タスクをスケジュールするためにManagedScheduledExecutorService.scheduleメソッドが呼び出された日時。- 戻り値:
- タスクの次の実行を開始する日付 / 時刻。
skipRun
この実行インスタンスをスキップする必要がある場合は true を返します。これは、タスクが遅れているために実行すべきでない場合、またはタスクが一時停止または一時停止されている場合に役立ちます。
このタスクがスキップされると、Future の結果の状態は
SkippedExceptionをスローします。未チェックの例外はSkippedExceptionでラップされます。- パラメーター:
lastExecutionInfo- タスクの最後の実行に関する情報。タスクがまだ実行されていない場合、この値は null になります。scheduledRunTime- このタスクの実行が開始されるようにスケジュールされている日付 / 時刻。- 戻り値:
- タスクをスキップして再スケジュールする必要がある場合は true。