public interface TriggerManagedScheduledExecutorService に送信されると、タスクに登録されます。各メソッドは、不特定のコンテキストで実行されます。メソッドは、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;
}
}
| 修飾子と型 | メソッドと説明 |
|---|---|
DateSE | getNextRunTime(LastExecution lastExecutionInfo, DateSE taskScheduledTime) 次回タスクを実行する時間を取得します。 |
boolean | skipRun(LastExecution lastExecutionInfo, DateSE scheduledRunTime) この実行インスタンスをスキップする必要がある場合は true を返します。 |
DateSE getNextRunTime(LastExecution lastExecutionInfo, DateSE taskScheduledTime)
lastExecutionInfo - タスクの最後の実行に関する情報。タスクがまだ実行されていない場合、この値は null になります。taskScheduledTime - ManagedScheduledExecutorService.schedule メソッドを使用してタスクがスケジュールされた日時。boolean skipRun(LastExecution lastExecutionInfo, DateSE scheduledRunTime)
これは、タスクが遅れているために実行すべきでない場合、またはタスクが一時停止または一時停止されている場合に役立ちます。
このタスクがスキップされると、その Future の結果の状態は SkippedException をスローします。チェックされていない例外は SkippedException でラップされます。
lastExecutionInfo - タスクの最後の実行に関する情報。タスクがまだ実行されていない場合、この値は null になります。scheduledRunTime - タスクが最初に実行されるようにスケジュールされた日時。Copyright © 2019 Eclipse Foundation.
Use is subject to license terms.