Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Quartz says this cron expression is not valid?

Quartz 2.x documentation says

So cron expressions can be as simple as this: * * * * ? * or more complex, like this: 0/5 14,18,3-39,52 * ? JAN,MAR,SEP MON-FRI 2002-2010

But if I try

System.out.println(org.quartz.CronExpression.isValidExpression("* * * * ? * *"));

It says

false

Why?

Javadoc for the isValidExpression is http://quartz-scheduler.org/api/2.2.1/org/quartz/CronExpression.html

Ps. this question is NOT a duplicate of Verifying a cron expression is valid in Java

like image 564
Leo Avatar asked Nov 11 '14 19:11

Leo


2 Answers

The linked JavaDoc mentions this structure for cron expressions:

Field Name      Allowed Values       Allowed Special Characters

Seconds         0-59                 , - * /
Minutes         0-59                 , - * /
Hours           0-23                 , - * /
Day-of-month    1-31                 , - * ? / L W
Month           1-12 or JAN-DEC      , - * /
Day-of-Week     1-7 or SUN-SAT       , - * ? / L #
Year (Optional) empty, 1970-2199     , - * /

Your cron expression is "* * * * ? * *" with a ? on the 5th position for Month. As you can see, this character is not allowed there.

like image 148
Tom Avatar answered Oct 15 '22 07:10

Tom


The JavaDoc you mentioned states that the ? character is allowed only for day-of-month and day-of-week fields. You are using it in Month field.

like image 22
Bohuslav Burghardt Avatar answered Oct 15 '22 07:10

Bohuslav Burghardt