I have a report creator program made in Java that needs to run every Monday and I used Quartz for my scheduling part. The trick is, the amount of reports needed to be generated varies; depending if the Monday is the first of the month, or the succeeding Mondays.
To achieve this, what i did is create a trigger for each Monday of the month with the first Monday pointing to a specific job class while the rest of the Mondays(triggers) point to another job class.
.withIdentity("trigger1", "group1")
.withSchedule(cronSchedule("0 1 0 ? 1/1 MON#1 *"))
.build();
.withIdentity("trigger2", "group1")
.withSchedule(cronSchedule("0 1 0 ? 1/1 MON#2 *"))
.build();
and so on until i reach
.withIdentity("trigger5", "group1")
.withSchedule(cronSchedule("0 1 0 ? 1/1 MON#5 *"))
.build();
It reached MON#5 because there could be 5 Mondays in a month; like this October. This is fine, it works (I think), but my question is this. Is there a way to combine my cron schedule so that I will only need one trigger for the succeeding mondays? Something like;
.withSchedule(cronSchedule("0 1 0 ? 1/1 MON#2,MON#3,MON#4,MON#5 *"))
If there is, please kindly enlighten me. If I’m just missing something, something in my programming, or if there exists an unknown page in the labyrinth which is the web that leads me to the truth, then kindly point me to the right direction.
Your kind words are greatly appreciated. Thanks
p.s: I included a cron tag even though it says it’s for UNIX computers. I believe there is little or no difference between Quartz cron and Unix cron. If there is, then please do tell.
It looks like there is no formal solution for your problem.
Here is a quote from Quartz 2.0 documentation:
There is also an open bug on this.