I have a customer check job. I could not find how to automatically set the job time to run on 10am only on Monday, Friday and Saturday. Is there a possible way to set it using Spring @Scheduled
?
Asked
Active
Viewed 1.5k times
7

ahmetcetin
- 2,621
- 1
- 22
- 38
-
I would recommend quartz-scheduler. http://www.quartz-scheduler.org/ – rsmets Jan 18 '19 at 00:42
1 Answers
16
I found the solution like this:
@Scheduled(cron = "0 0 10 * * MON,FRI,SAT")
public void dailyScheduleJob() {
/*
your code here
*/
}
Additionally, if the requested days are sequential such as Monday to Friday(a job running only on weekdays), this expression is shorter:
@Scheduled(cron = "0 0 10 * * MON-FRI")
public void dailyScheduleJob() {
/*
your code here
*/
}
It is also possible to represent days with numbers from 1-7. In this case 1 will be SUN, and 7 will be SAT and the same cron job above can be written like this:
@Scheduled(cron = "0 0 10 * * 2-6")
public void dailyScheduleJob() {
/*
your code here
*/
}

ahmetcetin
- 2,621
- 1
- 22
- 38