简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM