Skip to content
cron.surf

Run a Spring @Scheduled task every 5 seconds

The Spring expression for “Every 5 seconds” is */5 * * * * *. Below: config you can paste, the next run times, and what to watch out for. Spring’s @Scheduled(cron) takes six fields, seconds first, and needs every set day field to match.

*/5 * * * * *Open in tool

“Every 5 seconds”

@Scheduled method

@Scheduled
@Scheduled(cron = "*/5 * * * * *", zone = "UTC")
public void every5Seconds() {
    // job
}

Spring gotchas

Seconds come firstSpring expressions have six fields: second, minute, hour, day of month, month, day of week. A five-field crontab line is rejected.
Both day fields must match0 0 9 1-7 * MON is the first Monday of the month. In crontab the same fields mean days 1-7 or any Monday.
Sunday is 0 or 7Unlike Quartz, where Sunday is 1. Names (MON-SUN) are safest when you move expressions between the two.
Scheduling must be switched onAdd @EnableScheduling to a configuration class or @Scheduled methods never run. By default all tasks share one thread.

FAQ

What is the Spring cron expression for “Every 5 seconds”?

*/5 * * * * *. It reads: Every 5 seconds

Which time zone does a Spring schedule use?

In the JVM’s default time zone. Set zone = "Europe/Berlin" (any IANA name) on @Scheduled to pin it.

Can Spring cron run every 30 seconds?

Yes. Spring has a seconds field: */30 * * * * *.

Does Spring support L and #?

Yes, since Spring 5.3: L, LW, L-n and nW in day of month, and dL or d#n in day of week.