quartz: preventing concurrent instances of a job in jobs.xml

前端 未结 7 1677
既然无缘
既然无缘 2020-12-12 15:01

This should be really easy. I\'m using Quartz running under Apache Tomcat 6.0.18, and I have a jobs.xml file which sets up my scheduled job that runs every minute.

W

7条回答
  •  执笔经年
    2020-12-12 15:55

    Slight variation to scaramouche's solution.

    List jobs = jobExecutionContext.getScheduler().getCurrentlyExecutingJobs();
    for (JobExecutionContext job : jobs) {
        if (job.getTrigger().equals(jobExecutionContext.getTrigger()) && !job.getFireInstanceId().equals(jobExecutionContext.getFireInstanceId()) {
            logger.info("There's another instance running, so leaving" + this);
            return;
        }
    
    }
    

    scaramouche's solution fails when there is a single instance used for all JobExecutions( returning the singleton using a custom JobFactory class, rather than calling newInstance() for each execution)

提交回复
热议问题