Spring cron vs normal cron?

Spring Scheduled tasks are not in the same format as cron expressions.

They don’t follow the same format as UNIX cron expressions.

There are only 6 fields:

  • second,
  • minute,
  • hour,
  • day of month,
  • month,
  • day(s) of week.

Asterisk (*) means match any.
*/X means “every X” (see examples).

Numeric days of the week do not work for me. Besides, “MON-FRI” is much easier to read.
Here are some example expressions:

"0 0 18 * * MON-FRI" means every weekday at 6:00 PM. 

"0 0 */1 * * *" means every hour on the hour.

"0 0 */8 * * *" means every 8 hours on the hour.

"0 0 12 1 * *" means 12:00 PM on the first day of every month. 

Here you can find some additional information.

Also you may find the spring documentation useful.

Leave a Comment