我没有JobExecutionContext
。如果我使用getCurrentlyExecutingJobs
但不过滤getFireTime
会怎样?就像下面的方法一样。
我正在寻找How to check whether Quartz cron job is running?的灵感。
/**
*
* @param jk JobKey
* @return
* @throws SchedulerException
*/
public boolean isJobRunning(JobKey jk)
throws SchedulerException {
List<JobExecutionContext> currentJobs = this.getJobScheduler().getCurrentlyExecutingJobs();
for (JobExecutionContext jobCtx : currentJobs) {
String thisJobName = jobCtx.getJobDetail().getKey().getName();
String thisGroupName = jobCtx.getJobDetail().getKey().getGroup();
if (jk.getName().equalsIgnoreCase(thisJobName) && jk.getGroup().equalsIgnoreCase(thisGroupName)
//&& !jobCtx.getFireTime().equals(this.getJobScheduler().getContext().getFireTime())
) {
return true;
}
}
return false;
}
}