Quick revision
The short answer
Spring Boot's default ThreadPoolTaskScheduler has a pool size of 1, so all three @Scheduled methods share a single thread, and while the slow job waits 10 minutes for the external API, the other two cannot start. We fix it by giving the scheduler more threads with spring.task.scheduling.pool.size or our own TaskScheduler bean, putting timeouts on the API call, and, for long work, handing it to a bounded @Async executor.
What to remember
In this answer, we saw that the two jobs stop because Spring Boot's default scheduler has one thread, shared by every @Scheduled method, and the slow API call holds it for 10 minutes. A thread dump showing scheduling-1 in a socket read confirms it. We fixed it by raising spring.task.scheduling.pool.size or defining our own TaskScheduler, noted that virtual threads change the model and need a version check, put connect and read timeouts on the remote call, and saw how a bounded @Async executor can take long work off the scheduler thread.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Spring Boot's default ThreadPoolTaskScheduler has a pool size of 1, so all three @Scheduled methods share a single thread, and while the slow job waits 10 minutes for the external API, the other two cannot start. We fix it by giving the scheduler more threads with spring.task.scheduling.pool.size or our own TaskScheduler bean, putting timeouts on the API call, and, for long work, handing it to a bounded @Async executor.
Why this question is asked
This is a very common production surprise. Each job works perfectly on its own, and the problem only appears when one of them slows down and suddenly unrelated jobs stop too, which looks like a mystery until we know about the shared thread. Interviewers ask it to see whether we understand the threading model behind @Scheduled and whether we fix the cause, a blocking call with no limit, as well as the symptom. In this answer, we will recap how the scheduler runs tasks, reproduce the blocking, confirm it with a thread dump, and go through the fixes: more threads, virtual threads, timeouts and asynchronous execution.
1A Quick Recap of How Scheduled Tasks Run
When we enable scheduling, Spring registers every @Scheduled method with a TaskScheduler. The scheduler keeps a queue of tasks ordered by their next run time and a pool of threads that run them. When a task's time comes, a free thread takes it and calls the method; when the method returns, the thread is free again.
Spring Boot auto-configures this scheduler as a ThreadPoolTaskScheduler with a pool size of 1 and thread names starting with scheduling-. One thread is enough for many small, fast jobs, and it avoids surprising concurrency. But it also means the tasks are not independent: they take turns on the same thread.
2Reproducing the Blocking
Here are the three jobs. The report job calls a slow partner API that sometimes takes 10 minutes.
6 messages in order. Play them, or step through them one at a time.
The thread waits on the network for 10 minutes, and every other task waits for the thread.
Notice that every log line shows the same thread name, scheduling-1. While pushReport waits on the network, that thread is doing nothing useful, yet it is the only thread the scheduler has, so the other tasks queue up behind it.
3Confirming It With a Thread Dump
Before changing anything, we should prove the cause. A thread dump, taken with jcmd <pid> Thread.print, jstack, or the Actuator threaddump endpoint, shows what every thread is doing at that moment. During the stall we would see scheduling-1 in a socket read called from Jobs.pushReport, and no other scheduling- threads at all. That is the whole diagnosis: one thread, and it is stuck in the slow job.
4Fix 1: Give the Scheduler More Threads
The direct fix is a larger pool. In Spring Boot it is one property; with a TaskScheduler bean of our own we control it in code.
Now each task can run on its own thread, and the slow one only delays itself. Each individual task still does not overlap with itself, so pushReport will not start a second copy while the first is waiting. A pool slightly larger than the number of tasks that can be running at once is enough; there is no benefit in 50 threads for three jobs.
5Fix 2: Virtual Threads
With spring.threads.virtual.enabled=true on Java 21 or later, recent Spring Boot versions configure a SimpleAsyncTaskScheduler instead, which runs each task execution on a new virtual thread. Virtual threads are cheap threads managed by the JVM, and one that waits on a network call does not hold up an operating system thread. So a slow task no longer blocks the others at all.
This is attractive, but check your version for two details: how the scheduler handles fixed-rate tasks that overrun, since runs may overlap, and the fact that virtual threads are daemon threads, which is why Spring Boot offers spring.main.keep-alive for applications with nothing else keeping the JVM running.
6Fix 3: Put a Limit on the Slow Call
More threads remove the symptom, but the real problem is a call with no upper bound on how long it can take. If the partner API hangs forever, even a pool of four threads eventually fills with stuck calls. Every remote call in a scheduled job should have a connect timeout and a read timeout.
With a 60-second read timeout, the worst case is a one-minute delay and an exception that the job can log and retry on its next run. That is a failure we can see and alert on, instead of a silent ten-minute stall.
7Fix 4: Run Long Work Asynchronously on a Bounded Executor
When a job is legitimately long, another option is to let the scheduled method only trigger the work and hand it to a separate executor, so the scheduler thread returns at once. With @EnableAsync, a method on another bean marked @Async("reportExecutor") runs on that named executor. The executor should be bounded, for example 2 threads and a small queue, so a backlog of slow uploads cannot grow without limit.
But there is a catch: once the work is asynchronous, the scheduler no longer waits for it, so a new run can start while the previous upload is still going. If that matters, the job needs its own guard, such as a flag or a lock, or we should keep it synchronous on a larger scheduler pool instead.
8Follow-up questions
Why does Spring Boot default to a single scheduler thread?
Because it is the safest default. With one thread, scheduled tasks never run concurrently with each other, so jobs that touch the same data cannot interfere. The cost is that one slow task delays the others, which is why services with several independent jobs should set the pool size deliberately.
Do scheduled tasks use the same threads as web requests?
No. Scheduled tasks run on the scheduler's threads, not on the servlet container's request threads, so a slow job does not directly block requests. It can still hurt requests indirectly by holding database connections from the shared pool or using CPU, which is a separate reason to keep scheduled work light.
Is increasing the pool size always safe?
Mostly, but it changes one assumption: tasks that used to take turns can now run at the same time. If two jobs update the same rows or share a non-thread-safe object, we need to check them before raising the pool size.
9Conclusion
In this answer, we saw that the two jobs stop because Spring Boot's default scheduler has one thread, shared by every @Scheduled method, and the slow API call holds it for 10 minutes. A thread dump showing scheduling-1 in a socket read confirms it. We fixed it by raising spring.task.scheduling.pool.size or defining our own TaskScheduler, noted that virtual threads change the model and need a version check, put connect and read timeouts on the remote call, and saw how a bounded @Async executor can take long work off the scheduler thread.
Open with
By default, Spring Boot's ThreadPoolTaskScheduler has a pool size of one, so all three scheduled methods share a single thread, scheduling-1. When the report job waits ten minutes on the external API, that thread is busy, and the other two jobs just sit in the queue until it returns.
Then, if they want more
A thread dump would show scheduling-1 in a socket read inside the report method and no other scheduling threads. The first fix is more threads: spring.task.scheduling.pool.size of, say, four, or my own ThreadPoolTaskScheduler bean. Each task still won't overlap with itself, but they no longer block each other.
With virtual threads enabled, recent Boot versions use a SimpleAsyncTaskScheduler that runs each execution on a virtual thread, which also solves it, though I would check how that version treats overrunning fixed-rate tasks.
The more important fix is a timeout on the API call, a connect timeout and a read timeout of maybe 60 seconds, because an unbounded call will eventually fill any pool.
And if the work is genuinely long, I can trigger it from the scheduled method and run it with @Async on a small bounded executor, adding a guard if runs must not overlap.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Batch reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A Spring Boot service has three @Scheduled methods. One of them calls a slow external...": https://scrivio-interview-library.netlify.app/spring-boot/scheduling/3cdb38b296/