@EnableScheduling activates Spring's scheduled task support. Without it, methods annotated with @Scheduled are never run. Put it on a @Configuration class or your @SpringBootApplication class, and Spring registers a post-processor that finds @Scheduled methods and runs them on a task scheduler at a fixed rate, a fixed delay or a cron expression.
It covers in-process scheduling only. It does not persist jobs or coordinate multiple application instances.
The annotation imports SchedulingConfiguration, which registers a ScheduledAnnotationBeanPostProcessor. That processor looks at every bean for @Scheduled methods. Spring Boot does not enable it automatically, so the annotation is always required.
Scheduled methods must be void (or ignore the return value) and take no arguments. They must live on Spring-managed beans.
| Option | Meaning |
|---|---|
fixedRate | Start times are a fixed interval apart, measured from the previous start |
fixedDelay | Wait a fixed time after the previous run completes |
initialDelay | Delay before the first run |
cron | Six-field expression: second, minute, hour, day of month, month, day of week |
zone | Time zone for the cron expression, default is the server zone |
Spring cron has six fields, with seconds first, unlike the five-field Unix crontab. Values can come from properties, for example @Scheduled(cron = "${jobs.report.cron}"), and "-" disables a task.
By default, Spring Boot creates a ThreadPoolTaskScheduler with a pool size of one thread. A slow job then delays all the others. Configure it in application.properties:
On Spring Boot 3.2 and later with Java 21 you can run on virtual threads by setting spring.threads.virtual.enabled=true. With fixedRate, a task that runs longer than its interval does not overlap with itself on the same scheduler; the next run starts late instead.
When properties are not enough, implement SchedulingConfigurer and supply your own scheduler. This lets you set a thread name prefix, an error handler or a graceful shutdown wait.
The error handler receives exceptions thrown by scheduled methods, which is a good place for metrics or alerting. Waiting for tasks on shutdown lets a running job finish before the application stops.
Each application instance runs its own scheduler, so a job in a service with three replicas executes three times. Options include a distributed lock library such as ShedLock, a database-backed scheduler such as Quartz, or a Kubernetes CronJob. Choose one before deploying @Scheduled jobs that send emails or charge customers.
@EnableScheduling is missing, or the class is not a Spring bean.@Scheduled method is logged and the schedule continues, so check the logs and add your own error handling.@ConditionalOnProperty or place @EnableScheduling in a separate configuration class that tests can exclude.@EnableScheduling needed in Spring Boot?Yes. Boot configures the scheduler thread pool but does not turn scheduling on without the annotation.
fixedRate measures from the start of one run to the start of the next, while fixedDelay measures from the end of one run to the start of the next.
No. They take no arguments; read the data they need from injected fields.
Combine @Async with @EnableAsync, or increase the scheduler pool size.
@EnableScheduling registers the processor that runs @Scheduled methods. Set a suitable pool size, pick between fixedRate, fixedDelay and cron, and use a lock or external scheduler when the application runs on more than one instance.