I have successfully developed a application with SpringBoot and Quartz which executes only a single job using a Cron expression defined for that particular job. My implementation is largely based on the information found in following article.
https://chynten.wordpress.com/2016/06/17/quartz-with-databse-and-spring-4/
There, as you can see, the job triggering is done using a bean which encapsulates the cron expression.
@Bean
public Trigger simpleJobTrigger(@Qualifier("simpleJobDetail") JobDetail jobDetail) {
CronTriggerFactoryBean factoryBean = new CronTriggerFactoryBean();
factoryBean.setJobDetail(jobDetail);
factoryBean.setStartDelay(0L);
factoryBean.setName("test-trigger");
factoryBean.setStartTime(LocalDateTime.now().toDate());
factoryBean.setCronExpression("0/20 * * * * ?");
factoryBean.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW);
try {
factoryBean.afterPropertiesSet();
} catch (ParseException e) {
e.printStackTrace();
}
return factoryBean.getObject();
}
Now, I am in the need of creating multiple jobs which should be triggered based on their own cron expressions. In above case, the entire project had only one cron, hence I had no issues there. But now, different jobs should have different schedulings.
How can I extend my current implementation to support multiple jobs with different crons? Yes, I did some research on this, but couldn't find any information on how to configure Spring boot beans to cater my requirement.
Some examples have used quartz JobBuilder
to define jobs. Is that the way I should follow or can I extend my current implementation to support multiple jobs?
The question in following link looks quite similar, but I cannot understand how to pass different cron expressions and another instructions like misfire instructions to each job separately.
Autowiring in Quartz multiple Jobs with Spring Boot not working