Scheduler not running in Spring Boot
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
When a scheduled method does not run in Spring Boot, the cause is usually one of a few predictable issues: scheduling was never enabled, the class is not a Spring-managed bean, the trigger never matches, or the scheduler thread is blocked. The fastest way to debug it is to reduce the problem to a minimal working scheduled method and add evidence with logs.
Start with the Smallest Working Example
A scheduled method only runs if scheduling is enabled and the method belongs to a Spring bean.
If @EnableScheduling is missing, the method never runs. If the class is not a bean, Spring never sees the annotation.
Make Sure Spring Owns the Class
@Scheduled works through Spring bean management. That means the annotated class must be discovered by component scanning or created through configuration.
This works because Spring creates the bean. By contrast, calling new CleanupJob() yourself elsewhere in the code creates a plain Java object that the scheduler ignores.
Verify the Trigger Type
A scheduler that seems idle may actually be waiting on a trigger you did not mean to configure. fixedRate, fixedDelay, and cron behave differently.
In Spring, cron expressions include a seconds field. That catches many developers who copy a five-field Unix cron expression and expect it to work unchanged.
If you are debugging, temporarily switch to a short fixedRate schedule so you can observe behavior quickly.
Add Logging Around the Method
Do not debug this by staring at the code and waiting. Add explicit logs.
If no log appears, the problem is likely registration or configuration. If logs appear later than expected, the method may be blocked or waiting on thread capacity.
Long-Running Jobs Can Block the Default Scheduler
A job that takes a long time can make it look as if the scheduler stopped. If multiple tasks share too few scheduler threads, one slow method can delay the others.
This becomes important when scheduled work performs network calls, file I/O, or long database operations.
Watch for Self-Inflicted Design Problems
A scheduled method should stay small and observable. If it contains a large chain of blocking work with no logs and no timing information, it becomes hard to tell whether the scheduler failed or whether the job ran once and got stuck.
As a practical debugging sequence:
- confirm
@EnableScheduling - confirm the class is a Spring bean
- replace the real trigger with a short
fixedRate - log entry and exit
- check thread-pool behavior if the job is slow
This sequence usually isolates the issue quickly.
Common Pitfalls
A common mistake is forgetting @EnableScheduling. Without it, @Scheduled has no effect.
Another is placing the scheduled method on a class that Spring does not manage. The annotation is only meaningful on a bean.
Cron syntax also causes confusion, especially because Spring uses a seconds field. A copied expression from another scheduler may never fire at the expected time.
Long-running tasks can make the scheduler appear broken when the real issue is thread starvation.
Summary
- Enable scheduling with
@EnableScheduling. - Put
@Scheduledmethods on Spring-managed beans. - Use the correct trigger type and remember Spring cron includes seconds.
- Add logs so you can prove whether the method is firing.
- Configure a scheduler thread pool when jobs can block or overlap.

