Search code examples
springcronquartz-schedulerjobs

Spring quartz: Run 4 or 5 jobs using the same cron trigger?


How do i run four or five jobs using the same quartz cron trigger.Extending the code must be easy as we will keep on adding the jobs as we go on.

So any implementation details for this particular scenario ?

Please help.


Solution

  • I think you have 2 choices here:

    1 - create a new trigger based on the same cron expression each time you add a new job. This could be achieved really easily using a wrapper bean (i.e. "MyCronJobScheduler") that has the cron expression as an instance, and use it to create a new trigger + job each time you call the MyCronJobScheduler.addJob() method of that bean...

    2 - use a parent / child pattern, where your cron trigger schedules a parent job, whose only purpose is to start the children jobs each time it's executed...(since you can fire jobs from another job, or from a trigger/job listener)

    Hope that helps.