7

For Quartz Cron, is it possible at all to specify a cronexpression that corresponds to:

Run every 6 minutes, starting from 9:12 AM until 5:37 PM.

I attempted to write the cronexpression 0 12-37/6 9-17 ? * * but this does only runs once an hour. I also understand that the cronexpression 0 /6 9-17 ? * * corresponds to Run every 6 minutes between the hours of 9 AM and 5 PM.

But is there any way to constrain the starting and ending minutes on that cronexpression? More generally, can I specify an arbitrary start and end time with the job in question running every n intervals of time?

Mike Bailey
  • 12,479
  • 14
  • 66
  • 123
  • 2
    5 PM is hour 17 (not 14). `0 12-37/6 9-17 * * *` should do 9:12, 19, 24, 30, and 36 skip to 10:12 and run 5 times that hour. And keep on running 5 times an hour until 5:36 PM. – Lee Meador Jun 05 '13 at 20:45

1 Answers1

8

You can do it with 3 cron strings:

0 12-59/6 9 * * *
0 /6 10-16 * * *
0 0-37/6 17 * * *

Give them all the same task to run.

Lee Meador
  • 12,829
  • 2
  • 36
  • 42
  • oh dear please explain it. I have read it here but still confused http://quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger – AZ_ Sep 27 '13 at 12:33
  • I would suggest you ask Stack Overflow specific questions. Or perhaps you should just Google for more Quartz tutorials or a good cron tutorial. The repeated event timing in Quartz can be done very much the same as with cron. – Lee Meador Sep 27 '13 at 14:45
  • 1
    Thnx. Got answer here http://stackoverflow.com/questions/19051350/run-quartz-scheduler-job-with-specific-start-end-date-and-within-time-constrain/19058302?noredirect=1#19058302 – AZ_ Oct 03 '13 at 02:36
  • @LeeMeador I am sorry but cronmaker.com says all these expressions are invalid. I tried to generate next run dates using Cronmaker. Can you explain? – Bhushan Firake May 16 '15 at 17:43
  • @BhushanFirake cronmaker.com uses Quartz cron format. Evidently it does not allow using the dash and the slash together. – Lee Meador Jul 21 '15 at 18:06