Is it possible to create an expression for quartz scheduler in java which runs the job every 15 minutes but should skip the job runs from Saturday night 9PM to Sunday morning 6AM? So it will be like the job will run all 7 days a week every 15 minutes but should not run from Saturday 9PM to Sunday 6AM (for some maintenance activity at that time).
1 Answer 1
You can use a Quartz Calendar to exclude certain days and/or time periods. To support your use-case, you have two choices:
Implement a custom calendar by implementing the
org.quartz.Calendaror extendingorg.quartz.BaseCalendar. Internally your custom calendar can use two CronCalendar implementations described below.Use two "chained" CronCalendars. By chaining, I mean using one calendar as the base calendar of the other calendar. The first calendar will exclude Saturdays 9pm to midnight, the second will exclude Sundays 00am to 6am. These are the cron expression used by these two calendars:
-
- 21-23 ? * SAT
-
- 00-05 ? * SUN
Here are a few examples showing how to use calendars in your code:
http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/tutorial-lesson-04.html
https://www.javarticles.com/2016/06/quartz-calendar-example.html