每天 1:01:am 的 Spring cron 表达式 [英] Spring cron expression for every day 1:01:am

查看:48
本文介绍了每天 1:01:am 的 Spring cron 表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据 Spring cron 表达式按固定时间表执行我的代码.我希望代码每天在 1:01:am 执行.我尝试了以下表达式,但这并没有让我兴奋.这里的语法有什么问题?

I'm trying to have my code execute on a fixed schedule, based on a Spring cron expression. I would like the code to be executed every day at 1:01:am. I tried the following expression, but this didn't fire up for me. What's wrong with the syntax here?

@Scheduled(cron = "0 1 1 ? * *")
public void resetCache() {
    // ...
}

推荐答案

尝试:

@Scheduled(cron = "0 1 1 * * ?")

您可以在下面找到来自 spring 论坛的示例模式:

Below you can find the example patterns from the spring forum:

* "0 0 * * * *" = the top of every hour of every day.
* "*/10 * * * * *" = every ten seconds.
* "0 0 8-10 * * *" = 8, 9 and 10 o'clock of every day.
* "0 0 8,10 * * *" = 8 and 10 o'clock of every day.
* "0 0/30 8-10 * * *" = 8:00, 8:30, 9:00, 9:30 and 10 o'clock every day.
* "0 0 9-17 * * MON-FRI" = on the hour nine-to-five weekdays
* "0 0 0 25 12 ?" = every Christmas Day at midnight

Cron 表达式由六个字段表示:

Cron expression is represented by six fields:

second, minute, hour, day of month, month, day(s) of week

(*) 表示匹配任何

*/X 表示每个 X"

?(无特定值") - 当您需要在允许字符的两个字段之一中指定某些内容时很有用,但另一个字段中不允许.例如,如果我希望我的触发器在一个月的某一天(比如 10 号)触发,但我不在乎那一天是一周中的哪一天,我会在当天输入10"-月字段和?"在星期字段中.

? ("no specific value") - useful when you need to specify something in one of the two fields in which the character is allowed, but not the other. For example, if I want my trigger to fire on a particular day of the month (say, the 10th), but I don't care what day of the week that happens to be, I would put "10" in the day-of-month field and "?" in the day-of-week field.

PS:为了使它工作,请记住在您的应用程序上下文中启用它:https://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/scheduling.html#scheduling-注释支持

PS: In order to make it work, remember to enable it in your application context: https://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/scheduling.html#scheduling-annotation-support

这篇关于每天 1:01:am 的 Spring cron 表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆