My Spring service loooks like
@Scheduled( cron="0 0 7 * * SUN")
public void doSomething() {
// do something
}
I understand you can't have the 7th value which is reserved for specifying a year. using a expression can I tell spring to just run once a year at a particular time say 25th Dec 6 am in 2020 ?
Thanks
Yes, you can. Just have a look at this answer. In short, you can use the format:
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).
you can pass month basis it will run only once in year
@Schedule(cron="0 0 0 25 12 ?") --- it will run 25th December every year
public void CronExpression(){
//your logic
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With