Quartz cron trigger for every two hours between 8 AM to 6 PM and once at 11:59 PM

2.4k Views Asked by At

I have been trying to add the requirement in the quartz cron trigger.Below are the expressions i have come with ,

0 0 8,10,12,14,16,18 ? * *

0 0 8-18/2 ? * *

Are the above ones correct.Also How do I add the 11:59 PM trigger in the above.

Please help

1

There are 1 best solutions below

1
On BEST ANSWER

There are two things you can do.

First, you could run all of them on the hour and the 11:59 PM becomes 0:00:

0 0 0,8,10,12,14,16,18 ? * *

Perhaps running all the other ones minute earlier would be better:

0 59 7,9,11,13,15,17,23 ? * *

You could even add code in the job that delays a minute if its not almost midnight.

Other than that you can have two Quartz timers running the same job:

0 0 8,10,12,14,16,18 ? * *

and

0 59 23 ? * *