Is it possible to have a (Quartz)scheduler with cron expression that triggers after every 5 days including the today's date. For e.g.. if I am schedule a job on Dec 14, 2016 with an interval of 5 days, then it should be triggered on Dec 14, Dec 19, Dec 24, Dec 29, Jan 3, Jan 8, Jan 13, Jan 18, Jan 23, Jan 28, Feb 2 and so on.... ? I tried "17 33 15 14/5 * ? *" but not giving accurate result. Kindly HELP !!!
-
why you doesn't get accurate result? what's wrong with it. – Puchacz Dec 16 '16 at 20:04
-
Althought your query is correct it won't work as you expected. I think it's not possible by using CRON syntax. It's becouse you would like to start counting from concrete date (14.12.2016...). Cron counting always from begining of the part of date. By writing 14/5 you defined that first day of your month is 14 so every next month will be started from 14. And it will properly evaluate to 19, 24 and so on.. but... there is one more problem, Becouse evaluator always start from 14, your date will always be the same, it won't 'float'. To do it, you will need different kind of evaluator. – Puchacz Dec 16 '16 at 23:28
1 Answers
CronTrigger is unsuitable for this kind of schedules because these cannot be expressed using a cron expression. What you want to do is use the CalendarIntervalTrigger instead that is specifically tailored for these purposes.
I am attaching a screenshot of a CalendarIntervalTrigger editor in our Quartz scheduler management and monitoring tool (QuartzDesk).
As you can see, all you need to do is:
- Set the trigger's start datetime to Dec 14, 2016.
- Set the repeat interval unit to 'Day'.
- Set the repeat interval to 5 (i.e. 5 days).
Next to the editor window, there is a view that shows you calculated next fire time for the trigger. Dec 14th and Dec 19th are missing in the list, because today is Dec 20 and the view shows you future trigger fire times only.
The actual Java code to create a CalendarIntervalTrigger programatically is similar to the code that you use to create a CronTrigger so I am not including it here. The main point is that you have to use a different trigger type and set its the two properties as mentioned above.

- 1,808
- 1
- 15
- 18
-
I used this... CalendarIntervalScheduleBuilder schedule = calendarIntervalSchedule().withIntervalInDays((int) interval); trigger = newTrigger().withIdentity(jobName, groupName).startAt(startAt).withSchedule(schedule.inTimeZone(TimeZone.getTimeZone(timezoneId)).withMisfireHandlingInstructionDoNothing()).build(); – Alok Kumar Dec 21 '16 at 04:34
-
I am glad it works for you. If my answer helped you , please consider ticking it as an accepted answer. Thanks. – Jan Moravec Dec 21 '16 at 11:01