我是Quartz 2.1的新手,对此有疑问。我的工作如下
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class HelloJob implements Job {
public void execute(JobExecutionContext arg0) throws JobExecutionException {
我创建了两个作业,如下所示
JobDetail jobDetail = JobBuilder.newJob(HelloJob.class).withIdentity("Job1").build();
JobDetail jobDetail2 = JobBuilder.newJob(HelloJob.class).withIdentity("Job2").storeDurably().build();
Trigger trigger = TriggerBuilder.newTrigger().forJob(jobDetail).withSchedule(
SimpleScheduleBuilder.simpleSchedule()
.withIntervalInSeconds(5).repeatForever()).build();
Trigger trigger2 = TriggerBuilder.newTrigger().forJob(jobDetail2).withSchedule(
SimpleScheduleBuilder.simpleSchedule()
.withIntervalInSeconds(10).repeatForever()).build();
SchedulerFactory factory = new StdSchedulerFactory("quartz.properties");
Scheduler scheduler = factory.getScheduler();
scheduler.start();
scheduler.scheduleJob(jobDetail, trigger);
scheduler.scheduleJob(jobDetail2, trigger2);
如您所见,job1每5秒执行一次,job2每10秒执行一次。我想要的是,如果job1需要10秒以上完成,job2将执行直到job1完成。但实际上,job2仍在执行,而job1没有完成。你可以帮助我吗?
P/s: this is the quartz.properties:
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 2
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
答案 0 :(得分:0)
安排工作如下:
scheduler.start();
scheduler.addJob(jobDetail, true);
scheduler.scheduleJob(trigger);
scheduler.scheduleJob(trigger2);
您的代码的其他部分很好。