Reputation: 41
Is it possible to create a Cron Expression that runs every two days and ignore weekends? What I would like to achieve is basically this expression 0 0 9 1/2 * ?
but ignoring the weekends. I validate my expressions in the following website http://www.cronmaker.com/
It must have a 48h interval.
Thanks!
Upvotes: 1
Views: 3092
Reputation: 1880
I think you can safely use a single CronTrigger and all you need to do is to associate the trigger with a Quartz Calendar that excludes weekends. Quartz distribution comes with multiple Calendar implementations. You may want to check the WeeklyCalendar that allows you to exclude particular week days.
Providing the cron expression is: 0 0 9 1/2 * ?, your job will fire on Mon, Wed, Fri, (Sun will be ignored), Tue, Thu, (Sat will be ignored), Mon, ...
I think this should work. You can also try the CalendarIntervalTrigger with repeat interval unit = day, repeat interval = 2 and the same Calendar that excludes weekends.
Upvotes: 1
Reputation: 999
I have an other answer for you. Maybe simpler.
Basically in Quartz you have three step to run a job :
If you want to use your expression (e.g.: 0 0 9 1/2 * ?
) but ignore the week-end :
org.quartz.TriggerListener
implementing the rule that you don't want the trigger to fire the week-end.A org.quartz.TriggerListener
is an interface you can implements to add some rules other your triggers and jobs (see http://www.quartz-scheduler.org/documentation/quartz-1.x/tutorials/TutorialLesson07)
You must use the TriggerListener#vetoJobExecution
method to implement your specif rules
Upvotes: 0