How to fire the job on first monday of month using

2019-07-21 08:48发布

Now I have the following declaration:

@Scheduled(cron = "0 0 12 ? * MON#1")
protected synchronized void execute() {...}

and it doesn't work:

at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.5.9.RELEASE.jar:1.5.9.RELEASE]
Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'execute': For input string: "2#1"
    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.processScheduled(ScheduledAnnotationBeanPostProcessor.java:461) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.postProcessAfterInitialization(ScheduledAnnotationBeanPostProcessor.java:331) ~[spring-context-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:423) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1633) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    ... 19 common frames omitted

Please, help to make it working

3条回答
贪生不怕死
2楼-- · 2019-07-21 09:35

the expression is wrong use @Scheduled(cron = "0 0 0 ? * 2#1 *")

Refer the below for more info on this

https://stackoverflow.com/a/26147143/3724760

查看更多
该账号已被封号
3楼-- · 2019-07-21 09:36

The pattern is a list of six single space-separated fields: representing
second,
minute,
hour,
day,
month,
weekday.
Month and weekday names can be given as the first three letters of the English names.

So a Monday in the first 7 days of the month should generate what you are after.

"0 0 12 1-7 * MON"

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/support/CronSequenceGenerator.html

查看更多
叼着烟拽天下
4楼-- · 2019-07-21 09:41

This may work for you

* 6 * 12/1 1

For description check here

https://cronexpressiondescriptor.azurewebsites.net

查看更多
登录 后发表回答