【问题标题】:@Scheduled running at 16:00@预定于16:00运行
【发布时间】:2021-04-18 12:23:06
【问题描述】:

我在 SpringBoot 中创建了这个方法

    @Scheduled(cron = "0 16 * * * *")
    public void sendMsg() {
}

每天下午16:00(中午)执行:

而是每天执行几次

【问题讨论】:

  • //秒、分、小时、日、月、工作日-这里是@Schedule中每个*的解释

标签: spring spring-boot scheduled-tasks


【解决方案1】:

正如之前的答案所指出的,您的表达式不是有效的“Spring 表达式”,而是 unix 表达式。 Spring 使用 Quartz-type 将秒值作为第一个参数添加:

+-------------------- second (0 - 59)
|  +----------------- minute (0 - 59)
|  |  +-------------- hour (0 - 23)
|  |  |  +----------- day of month (1 - 31)
|  |  |  |  +-------- month (1 - 12)
|  |  |  |  |  +----- day of week (0 - 6) (Sunday=0 or 7)
|  |  |  |  |  |  +-- year [optional]
|  |  |  |  |  |  |
*  *  *  *  *  *  * command to be executed

Source

【讨论】:

    【解决方案2】:

    应该是这样的:

    @Scheduled(cron = "0 0 16 * * *")
        public void sendMsg() {
    }
    

    【讨论】:

      【解决方案3】:

      我觉得你的表情应该是0 0 16 ? * * *

      有许多在线 cron 求值器可用于求值或创建表达式。

      【讨论】:

        猜你喜欢
        • 2016-05-28
        • 1970-01-01
        • 1970-01-01
        • 2021-07-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-03-03
        相关资源
        最近更新 更多