简体   繁体   English

Quartz Scheduler-使用JobDataMap进行作业链接

[英]Quartz Scheduler - Job Chaining with JobDataMap

I'm new to Quartz Scheduler and have the following requirement 我是Quartz Scheduler的新手,并具有以下要求

I need to have two jobs. 我需要两个工作。 based on the first job response, the second job need to be triggered immedeately. 根据第一个作业的响应,第二个作业需要立即触发。

I read different appraches for jon chaining and after going through the list, I finally settled down for JobDataMap approach. 我阅读了有关jon链接的各种方法,并仔细阅读了清单之后,终于适应了JobDataMap方法。

First Job : 第一份工作 :

public void method callJob()
JobDetail jobDetail = JobBuilder.newJob(DataProcurementJob.class)
                                  .withIdentity("Job1, "JobGroup1")
                                  .build();

            JobDataMap jobDataMap = jobDetail.getJobDataMap();
            jobDataMap.put("NEXT_JOB", "com.abc.test.Jobs.DataLoadJob");
            jobDataMap.put("PARAM1", "VALUE1");
            jobDataMap.put("PARAM2", "VALUE2");

            Trigger trigger = TriggerBuilder.newTrigger()
                             .withIdentity("DataProcurementTrigger1",                        "DataProcurementTrigger")
                              .withSchedule(
                            CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
                              .build() ;

            //Schedule it

            Scheduler scheduler = new StdSchedulerFactory().getScheduler();
            scheduler.scheduleJob(jobDetail,trigger);
            scheduler.start();

}

Execute Method class : 
public job1Class implements job {
If (condition == false){
      keep running Job1
}
else 
{ 
Call Job2
}
}

I have implemented the above code, but second job is not getting launched. 我已经实现了上面的代码,但是第二项工作没有启动。 I'm printing a statement in Job 2. 我正在作业2中打印一份声明。

Can somebody please advise on how to invoke the secon job only once? 有人只能建议一次如何调用secon作业吗?

Instead of using JobDataMap, You can try with JobChainingJobListener: 您可以尝试使用JobChainingJobListener来代替JobDataMap:

JobChainingJobListener chain = new JobChainingJobListener();
chain.addJobChainLink(job1.getKey(), job2.getKey());

You have to schedule your job1 and add job2 to the scheduler: 您必须安排您的job1并将job2添加到计划程序中:

scheduler.add(job2, false);
scheduler.scheduleJob(job1, trigger);
scheduler.start();

and your job2 must be durable (param storeDurably). 并且您的job2必须是持久的(param storeDurably)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM