Add multiple triggers to single quartz job

前端 未结 3 1479
无人及你
无人及你 2021-02-05 16:06

I want to dynamically add triggers to a job, but can\'t find any helpful methods off of Scheduler

I though i would just be able to call the scheduleJob method an repetit

相关标签:
3条回答
  • 2021-02-05 16:48
        CronTrigger trigger=null;
        CronTrigger trigger1=null;
        CronTrigger trigger2=null;
    
        JobDetail job = new JobDetail();
        job.setName("dummyJobName");
        job.setJobClass(ExampleJob.class);
    
        trigger = new CronTrigger();
        trigger.setName("AppTrigger");
        trigger.setGroup(job.getGroup());
        trigger.setJobName(job.getName());
        trigger.setJobGroup(job.getGroup());
        trigger.setCronExpression("*/2 * * * * ?");
    
        trigger1 = new CronTrigger();
        trigger1.setName("AppTrigger1");
        trigger1.setGroup(job.getGroup());
        trigger1.setJobName(job.getName());
        trigger1.setJobGroup(job.getGroup());
        trigger1.setCronExpression("*/2 * * * * ?");
    
        trigger2 = new CronTrigger();
        trigger2.setName("AppTrigger2");
        trigger2.setGroup(job.getGroup());
        trigger2.setJobName(job.getName());
        trigger2.setJobGroup(job.getGroup());
        trigger2.setCronExpression("*/2 * * * * ?");
    
        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
    
        scheduler.start();
        scheduler.addJob(job, true);
        scheduler.scheduleJob(trigger);
        scheduler.scheduleJob(trigger1);
        scheduler.scheduleJob(trigger2);
    
    0 讨论(0)
  • 2021-02-05 16:52

    You can call scheduleJob repeatedly. Just make sure that you give each Trigger a unique name/group.

    See TriggerBuilder.withIdentity: http://www.quartz-scheduler.org/docs/api/2.0.0/index.html

    0 讨论(0)
  • 2021-02-05 16:55

    This post gives a hint, but the conclusion ( schedulerInstance.add(trigger) ) is not valid as of Quartz 2.01.

    Instead use the following, after assinging the job to the trigger ( one way is using the TriggerBuilder's forJob method )

     schedulerInstance.scheduleJob( newTrigger )
    
    0 讨论(0)
提交回复
热议问题