3
votes

Quartz documentation gives an example for running a cron job on the last day of every month, like this:

0 15 10 L * ?   

Fire at 10:15am on the last day of every month

However, I'd like to run a cron job on the 1st AND Last day of the month. I would expect the cron would look somthing like this:

0 15 10 1,L * ?

But this syntax is not valid by quartz.

I couldn't find any proper/similar example in their tutorial. Any suggestions?

1
It seems a bug in Quartz because documentation says nothing about using L and commas to list days. Have you tried to use L,1 instead of 1,L?Pablo Lozano
In the documentation link :quartz-scheduler.org/documentation/quartz-2.x/tutorials/…. They mention - "When using the 'L' option, it is important not to specify lists, or ranges of values, as you'll get confusing/unexpected results." Probably you will have to setup two triggers on the same jobAbhishekAsh
@AbhishekAsh this comment in the documentation seems irrelevant to the question, as quartz clearly not supporting L with other values. It should have mention that rather than describing something ambiguous as "confusing/unexpected results".Elad Tabak

1 Answers

2
votes

So after some digging in quartz code I found this:

// throw an exception if L is used with other days of the month
if(exprOn == DAY_OF_MONTH && expr.indexOf('L') != -1 && expr.length() > 1 && expr.contains(",")) {
    throw new ParseException("Support for specifying 'L' and 'LW' with other days of the month is not implemented", -1);
}

org.quartz.CronExpression (quartz 2.2.2).

It seems 'L' is not supported for day-of-month with other days of the month. Too bad it's not anywhere in their documentation :(