4

私のSpringサービスは次のようになります

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

年を指定するために予約されている 7 番目の値を使用できないことを理解しています。式を使用して、2020 年の 12 月 25 日午前 6 時など、特定の時間に年に 1 回だけ実行するように春に指示できますか?

ありがとう

4

3 に答える 3

9

はい、できます。この答えを見てください。つまり、次の形式を使用できます。

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).
于 2016-02-11T10:54:55.427 に答える
6

年に一度だけ実行される月単位で渡すことができます

@Schedule(cron="0 0 0 25 12 ?") --- it will run 25th December every year 

public void CronExpression(){

//your logic

}
于 2017-02-15T07:12:54.080 に答える