Quartz error Both day fields are set
Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.
java.lang.RuntimeException: CronExpression '0 0 12 * * MON' is invalid.
Caused by: java.text.ParseException: Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.Message produced by running the expression through org.quartz.CronExpression from Quartz 2.5.2.
What it means
Quartz reads six or seven fields: second, minute, hour, day of month, month, day of week and an optional year. Exactly one of the two day fields must be ?, meaning “no specific value”. Quartz has no rule for combining a day of month with a day of week, so rather than guess, it refuses any expression where both are set.
A * counts as set. That is why 0 0 12 * * *, which reads as “every day at noon” to anyone used to Unix cron or Spring, fails with this message too.
Rejected expressions and their fixes
Each expression opens in the tester. The message under a rejected one is what Quartz 2.5.2 printed for it.
-
Rejected0 0 12 * * *Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.Use0 0 12 * * ?At 12:00.
Every day at noon.
*in day of month already means every day, so day of week becomes?. -
Rejected0 0 12 * * MONSupport for specifying both a day-of-week AND a day-of-month parameter is not implemented.Use0 0 12 ? * MONAt 12:00, on Mondays.
Mondays at noon. The day of week carries the meaning, so day of month becomes
?. -
Rejected0 0 9 1 * MONSupport for specifying both a day-of-week AND a day-of-month parameter is not implemented.
Unix cron reads this as the 1st of the month or any Monday. Quartz can’t say “or” across the day fields, so give the job two triggers.
-
Rejected0 0 9 1-7 * MONSupport for specifying both a day-of-week AND a day-of-month parameter is not implemented.Use0 0 9 ? * MON#1At 09:00, on the first Monday of the month.
Meant as the first Monday of the month? Quartz has
#for that:MON#1is the first Monday.
Questions
- Does
*count as setting a day field in Quartz? - Yes. Only
?leaves a day field unset, so*in both is rejected. Put?in one of them:0 0 12 * * ?or0 0 12 ? * *. - Which day field should get the
?? - The one you are not using. For a schedule by weekday, put
?in day of month:0 0 9 ? * MON-FRI. For a date, or every day, put it in day of week:0 0 9 15 * ?. - Does AWS EventBridge have the same rule?
- Yes. EventBridge cron expressions also need
?in exactly one of the two day fields, though AWS reports the problem with its own message.
Other Quartz errors
- Unexpected end of expression.Quartz: Five fields instead of six
- '?' can only be specified for Day-of-Month -OR- Day-of-Week.Quartz:
?in the wrong place - Day-of-Week values must be between 1 and 7Quartz: Sunday written as 0
- Hour values must be between 0 and 23Quartz: A value out of range
- Increment >= 60 : 90Quartz: A step longer than the field
- Unexpected character: @Quartz:
@dailyand other shortcuts