我Spring的服务看起来像这样
@Scheduled( cron="0 0 7 * * SUN")
public void doSomething() {
// do something
}
我明白你不能使用第七个值来指定年份。那么使用一个表达式,我能否告诉Spring在特定时间运行一次,比如2020年12月25日上午6点?
谢谢。
我Spring的服务看起来像这样
@Scheduled( cron="0 0 7 * * SUN")
public void doSomething() {
// do something
}
我明白你不能使用第七个值来指定年份。那么使用一个表达式,我能否告诉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触发