问题
I am transferring files from a directory on a remote host and a trigger fires jobs when interval arrives for this job.But i want be sure that if a job still working on a storage (downloading of files not yet finished) when trigger fire time arrives ,quartz going to skip this interval.I try to use this c r on_trigger.MISFIRE_INSTRUCTION_DO_NOTHING but i seems it only for if there is no available thread for job.
public CronTrigger scheduleJob(RemoteJob job, String cronExpression,Date firstFireTime) throws SchedulerException, ParseException {
JobDetail jobDetail = new JobDetail(job.getDescription(), job.getName(), job.getClass());
CronTrigger crTrigger = new CronTrigger(
"cronTrigger", job.getName(), cronExpression);
scheduler.scheduleJob(jobDetail, crTrigger);
crTrigger.setStartTime(firstFireTime);
crTrigger.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING);
return crTrigger;
}
回答1:
Create a TriggerListener that tracks if one of your download jobs is running, and and then return true for vetoing the execution of the other type of job.
回答2:
I slightly modified the code above, it's worked.
/**
* not for cluster
*/
@Override
public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
try {
List<JobExecutionContext> currentlyExecutingJobs = context.getScheduler().getCurrentlyExecutingJobs();
for (JobExecutionContext jobContext : currentlyExecutingJobs) {
if (jobContext.getTrigger().equals(trigger) &&
jobContext.getJobDetail().getKey().equals(trigger.getJobKey())) {
return true;
}
}
} catch (SchedulerException ex) {
return true;
}
return false;
}
回答3:
I did as you say
public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) {
try {
List<JobExecutionContext> jobs =
context.getScheduler().getCurrentlyExecutingJobs();
for (JobExecutionContext job : jobs) {
if (job.getTrigger().equals(context.getTrigger()) &&
!job.getJobInstance().equals(this)) {
_logger.info("There's another instance running,So job discarded " + context.getJobDetail().getGroup()+ ":"+context.getJobDetail().getName());
return true;
}
}
} catch (SchedulerException ex) {
return true;
}
return false;
}
来源:https://stackoverflow.com/questions/6155665/how-to-skip-cron-trigger-firetime