Is this cronExpression correct?
Asked Answered
B

2

5

I don't know if the below expression is correct:

<property name="cronExpression" value="0  0  12  2  *  MON-FRI ?"/> 

I try to configure my trigger to fire every second day of every month, no matter the year, at noon, and the day of week has to be between Monday and Friday.

I'd really appreciate if someone could help me. Thanks in advance.

Bihari answered 15/12, 2010 at 23:21 Comment(1)
Did you mean "every second day" or "the second day of every month" (which your cronExpression suggests)?Pietro
P
5

I'm assuming you meant "every second day (every other day), as long as it's MON-FRI".

According to Quartz CronTrigger Tutorial:

'1/3' in the day-of-month field means "fire every 3 days starting on the first day of the month".

So, 1/2 would mean "fire every second day starting on the first day of the month". A cronExpression like 0 0 12 1/2 * MON-FRI * should then be close to what you want. Checking with

org.quartz.CronExpression.isValidExpression("0  0  12  1/2 * MON-FRI *")

...says that the expression is valid.

However, testing it a little further with:

CronExpression e = new CronExpression("0  0  12  1/2 * MON-FRI *");
e.isSatisfiedBy(new DateTime(2012, 9, 26, 12, 0, 0, 0).toDate());

...throws an exception:

> Exception in thread "main" java.lang.UnsupportedOperationException:
> Support for specifying both a day-of-week AND a day-of-month parameter
> is not implemented.

So, seems like jhouse is right and you just can't do that with a cronExpression.

Maybe something like this would work as a workaround: Quartz cron expression for cron triggers executed every Nth Hour/Day/Week/Month

Pietro answered 26/9, 2012 at 10:32 Comment(0)
S
4

You cannot specify both a day of month and a day of week - it is not supported.

Sirloin answered 29/1, 2011 at 3:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.