我的 Spring 服务看起来像
@Scheduled( cron="0 0 7 * * SUN")
public void doSomething() {
// do something
}
我知道您不能使用为指定年份而保留的第 7 个值。使用表达式我可以告诉 spring 每年在特定时间运行一次,比如 2020 年 12 月 25 日上午 6 点吗?
谢谢
我的 Spring 服务看起来像
@Scheduled( cron="0 0 7 * * SUN")
public void doSomething() {
// do something
}
我知道您不能使用为指定年份而保留的第 7 个值。使用表达式我可以告诉 spring 每年在特定时间运行一次,比如 2020 年 12 月 25 日上午 6 点吗?
谢谢
是的你可以。看看这个答案。简而言之,您可以使用以下格式:
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).
你可以按月计算它每年只运行一次
@Schedule(cron="0 0 0 25 12 ?") --- it will run 25th December every year
public void CronExpression(){
//your logic
}
当然
@Scheduled( cron="59 59 23 6 12 ? 2020")
public void doSomething() {
// do something
}
这将在 2020 年 12 月 6 日 23:59:59 被解雇