开发者

Is this cronExpression correct?

开发者 https://www.devze.com 2023-01-30 15:13 出处:网络
I don\'t know if the below expression is correct: <property name=\"cronExpression\" value=\"00122*MON-FRI ?\"/>

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 bet开发者_开发知识库ween Monday and Friday.

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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号