Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Significance of question mark in Java cron

Tags:

java

cron

crontab

Source Wikipedia:

Question mark (?) is used instead of '*' for leaving either day-of-month or day-of-week blank.

The above statement is not making much sense to me.

So if I write some cron as 0 0 0 ? * * then does it mean first of every month or it means it will execute daily?

It is a bit confusing as Java crons start with seconds while other crons start with minute.

like image 410
learner Avatar asked Jul 16 '12 07:07

learner


People also ask

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

It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week .

What is cron expression 0 * * * *?

Meaning of cron expression 0 * * * * *? I think it means the scheduler is expected to run every seconds.

What does asterisk mean in cron?

Asterisks indicate that the cron expression matches for all values of the field. For example, "*" in the minute field means every minute.

How do you read a cron expression?

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

According to the Quartz CronTrigger tutorial (Quartz is used by www.cronmaker.com, referenced above), the ? wildcard is only used in the day of month and day of week fields:

? ("no specific value") - useful when you need to specify something in one of the two fields in which the character is allowed, but not the other. For example, if I want my trigger to fire on a particular day of the month (say, the 10th), but don't care what day of the week that happens to be, I would put "10" in the day-of-month field, and "?" in the day-of-week field.

I guess * isn't appropriate here because * means execute on every day of the week, which contradicts the rule saying that it should only run on the 10th of the month.

like image 185
Dan King Avatar answered Sep 29 '22 21:09

Dan King