来源维基百科:
使用问号(?)代替'*',以留下日期或星期几空白.
上面的陈述对我来说没有多大意义.
所以如果我写一些cron,0 0 0 ? * *那么它是指每个月的第一个还是意味着它会每天执行?
这有点令人困惑,因为Java crons以秒开始,而其他crons以分钟开头.
我想安排一个方法每 24 小时运行一次,并且根据我的设置,它每 24 分钟执行一次。
我引用了下面的 URL,其中有不同的建议
链接 1建议<second> <minute> <hour> <day-of-month> <month> <day-of-week> <year> <command>
链接2建议minute hour day(month) month day(week)
下面是我的 Spring Boot 应用程序的 application.yml 中的 cron 设置。
cron: 工作: 表达式: 0 0 23 * * ?
有人可以帮助了解什么是正确的信息来源以及可以根据当前要求进行设置吗?
我的作业每隔指定的时间运行一次,但它每隔指定的时间运行一次,例如,如果我将作业设置为在 22:54 运行,它将从 22:54:00 到 22:54:59 每秒运行一次。我希望它只在指定的时间运行一次...非常感谢任何帮助
我的代码:
@Scheduled(cron = "* 54 22 * * ?")
public void getCompaniess() {
System.out.println(new Date()+" > Running testScheduledMethod...");
}
Run Code Online (Sandbox Code Playgroud)
输出:
Thu Mar 12 22:54:00 GMT 2020 > Running testScheduledMethod...
Thu Mar 12 22:54:01 GMT 2020 > Running testScheduledMethod...
.....
Thu Mar 12 22:54:59 GMT 2020 > Running testScheduledMethod...
我有一个方法,我希望使用 Spring 运行一次,它需要在给定java.util.Date(或LocalDateTime替代)上运行。我计划将方法应执行的所有日期保留到数据源。它应该异步运行。
一种方法是每天检查数据库中的某个日期,如果该日期已过且尚未执行,则执行该方法。有没有更好的办法?
我知道 Spring 提供了 aThreadPoolTaskScheduler和 a ThreadPoolTaskExecutor。我是ScheduledFuture schedule(Runnable task, Date startTime)从TaskScheduler界面看的。我是否需要创建一个RunnableSpring 托管 bean 来调用我的方法?或者是否有更简单的注释可以做到这一点?一个例子真的很有帮助。
(也看过这里。)
现在我有以下声明:
@Scheduled(cron = "0 0 12 ? * MON#1")
protected synchronized void execute() {...}
Run Code Online (Sandbox Code Playgroud)
它不起作用:
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
Run Code Online (Sandbox Code Playgroud)
请帮助使其正常工作