Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cron expression every 50 seconds in Quartz

I'm running my Jobs using Quartz with a cron expression every 50 seconds:

Cron_Expression = "0/50 * * * * ?"

What happens is that my job runs at the seconds: 50, 60, 50, 60,... and not every 50 seconds! and does not run at the second "0".

What is the right cron expression every 50 seconds starting at 0?

like image 984
Yosefarr Avatar asked Mar 17 '13 06:03

Yosefarr


People also ask

What is the use of * * * * * In cron?

* * * * * is a cron schedule expression wildcard, meaning your cron job should run every minute of every hour of every day of every month, each day of the week.

What does cron 0 * * * * * mean?

*/5 * * * * Execute a cron job every 5 minutes. 0 * * * * Execute a cron job every hour.

Does quartz use cron?

The cron triggers you can configure in the Orchestration Server Job Scheduler use a Quartz crontrigger class for deciding when to invoke job execution. This is based on the standard Quartz format that you can find further described on the KickJava website.

What is Quartz cron expression?

quartz. Trigger. A cron expression is a string consisting of six or seven subexpressions (fields) that describe individual details of the schedule. These fields, separated by white space, can contain any of the allowed values with various combinations of the allowed characters for that field.


1 Answers

The '/' syntax specifies the increment during the period and not a repeat interval. Admittedly a subtle and confusing difference.

In this case there is only one available increment (50 seconds) during the 1 minute period. The first number specifies the value to start with, in this case 0. Specifying '*' before the '/' is equivalent to specifying 0. So the job will only fire on the minute (0 and 60 are interchangeable) and at 50 seconds.

If the period can be divided by multiple increments, eg 0/10 then it will fire for each at each of those times, eg at 10, 20, 30 etc seconds.

If you want a job to trigger at a regular interval then you can use a Quartz SimpleTrigger with a repeatInterval specified.

like image 145
darrenmc Avatar answered Oct 05 '22 21:10

darrenmc