In Spring Boot, @Scheduled runs a method automatically on a repeating schedule: at a fixed rate, after a fixed delay, or at cron times. You turn it on with @EnableScheduling, and Boot supplies a configured task scheduler that you tune through spring.task.scheduling.* properties.
It suits simple in-application jobs such as cleaning caches or sending daily reports. This article covers what Spring Boot adds on top of the plain annotation: scheduler properties, virtual threads, monitoring and testing.
@Scheduled comes from the Spring Framework. Spring Boot auto-configures a ThreadPoolTaskScheduler (or, with virtual threads enabled, a SimpleAsyncTaskScheduler) as soon as @EnableScheduling is present, and applies your properties to it.
A new run starts every five seconds, measured from the start of the previous run.
The next run starts five seconds after the previous run finishes.
Spring cron has six fields (second, minute, hour, day of month, month, day of week). The expression above runs at the top of every hour. The original 0 0 * * * ? form also works because ? is accepted in the day fields. Add zone = "Europe/London" (or any zone id) for a predictable schedule.
Spring Boot reads these properties for the auto-configured scheduler:
The default pool size is 1, so tasks share one thread until you change it. Keep the schedules themselves in properties too:
With Spring Boot 3.2 and later you can set spring.threads.virtual.enabled=true (requires Java 21 or later). Boot then runs scheduled tasks on virtual threads, which is helpful when jobs spend most of their time waiting on I/O.
The job class holds only the trigger; the logic lives in a service you can test without any scheduler. Constructor injection makes the dependencies explicit.
With Spring Boot Actuator, expose the scheduledtasks endpoint to see every registered task and its trigger:
For tests, call the method directly and assert on the result. To verify that a schedule actually fires, use Awaitility around a short fixedRate set through a test property. Disable scheduling in unrelated tests by keeping @EnableScheduling in a configuration class that those tests do not load.
pool.size.No. It is part of spring-context, included by the starters.
Put the bean behind @Profile("prod"), or set the cron property to - in profiles where it should be disabled.
If the previous run takes longer than the interval, the next run starts only after it ends. Also check that other tasks are not using the only scheduler thread.
In Spring Boot, @Scheduled plus @EnableScheduling gives you simple recurring tasks with an auto-configured scheduler. Choose fixedRate, fixedDelay or cron, externalise schedules and pool size in properties, expose scheduledtasks for visibility, and add locking when the app runs on more than one instance.