gpt4 book ai didi

java - Spring 调度程序的 cron 表达式 - 每年只运行一次

转载 作者:搜寻专家 更新时间:2023-11-01 01:20:48 24 4
gpt4 key购买 nike

我的 Spring 服务看起来像

@Scheduled( cron="0 0  7 * * SUN")
public void doSomething() {
// do something
}

我知道您不能拥有为指定年份保留的第 7 个值。我可以使用表达式告诉 spring 每年只在特定时间运行一次吗?比如 2020 年 12 月 25 日上午 6 点?

谢谢

最佳答案

是的,你可以。看看this回答。简而言之,您可以使用以下格式:

0 0 6 6 9 ? 
| | | | | |
| | | | | |
| | | | | +----- any day of the week.
| | | | +------- 9th month (September).
| | | +--------- 6th day of the month.
| | +----------- 6th hour of the day.
| +------------- Top of the hour (minutes = 0).
+--------------- Top of the minute (seconds = 0).

关于java - Spring 调度程序的 cron 表达式 - 每年只运行一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35337198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com