私は、データベースからスケジュールジョブを読み取り、正常に動作するようにスケジュールするスケジューラエンジンに取り組んできましたが、データベース内の行は、特定のタイプのジョブの「構成」にすぎません。
FTPを取得するための特定の構成には
host: imagineryHost1.com
post: 22
そして、同じクラスの別の
host: imagineryHost2.com
post: 21
独自のトリガーと独自の個別のデータを持つ 2 つの FPTjob を作成します。
/**
BaseJob is an Abstract class extending QuartzJobBean used to handle our logging and
other requirements that need across all our jobs.
*/
public class FTPJob extends BaseJob {
/**
Called from executeInternal of QuartzJobBean
*/
@Override
public boolean execute1V(JobExecutionContext context) {
//Code to get Files from FTP.
}
}
これらは、TriggerBuilder と cron を使用してスケジュールされます。
@DisallowConcurrentExecution を追加すると、一度に実行できる FTPJob のインスタンスは 1 つだけになりますが、FTPJob の複数のインスタンスを実行できるようにする必要がありますが、そのクラスの特定の構成の 1 つのインスタンスのみに制限する必要があります。
進行方法に関するリードは高く評価されます:)
アップデート
ftom2の回答に基づいて、すべてのジョブ構成に独自のuniqueIDがあるため、掘り下げてTriggerListenerを見つけました.ieの実行からジョブを「拒否」できます。
public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
try {
Iterator<JobExecutionContext> it =
context.getScheduler().getCurrentlyExecutingJobs().iterator();
boolean found = false;
while(it.hasNext()) {
JobExecutionContext job = it.next();
if(trigger.getJobKey().equals(job.getJobDetail().getKey())) {
return false;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
これを処理するためにもう少し組み込まれている他の方法はありますか?