Using cron expressions
Task scheduling is done using cron expressions. A cron expression is a string which consists of six fields:
-
Second (not supported)
-
Minute: 0 - 59
-
Hour: 0 - 23
-
Day of the month: 1 - 31 or L (last day of the month), a W following a number or L means the weekday
-
Month: 1 - 12 or JAN - DEC
-
Day of the week: 0 - 7 or MON - SUN
The following operators can be used in the expression:
-
* (asterisk): every, i.e. first to last, e.g. * in the day of month field means every day
-
- (hyphen): inclusive range, e.g. MON-FRI means Monday to Friday
-
, (comma): and, e.g. SAT,SUN means Saturday and Sunday
-
/ (slash): interval, e.g. */4 in the hour field means every four hours
The following examples show valid cron expressions:
-
Daily execution at 23:30: 30 23 * * *
-
Daily execution at 23:00 on weekdays: 0 23 * * MON-FRI
-
Daily execution every four hours: 0 */4 * * *
-
Daily execution every hour from 08:00 till 17:00: 0 8-17 * * *
-
Weekly execution at 01:10 on Sundays: 10 1 * * SUN
-
Monthly execution at 01:00 on the first day of the month: 0 1 1 * *
-
Monthly execution at 23:30 on the last day of the month: 30 23 L * *
-
Execution at 23:30 on the last weekday of the quarter: 30 23 LW MAR,JUN,SEP,DEC *
See https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/support/CronExpression.html for the official documentation.