Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

A web service submits background tasks to a bounded pool configured with CallerRunsPolicy. During a slowdown, request latency for unrelated endpoints spikes and the server stops accepting connections. Explain and propose an alternative.

When the background pool is full, CallerRunsPolicy runs the rejected task on the thread that submitted it, which here is a Tomcat request thread. During the slowdown every request thread ends up doing slow background work, so no thread is left for unrelated endpoints, new connections wait in the accept queue, and the server appears to stop accepting them. The fix is to fail or shed background work explicitly with AbortPolicy, a metric and an alert, or, if we really want to slow callers, to use a bounded wait with a timeout.

Why this question is asked

This scenario is a good example of a setting that looks safe and causes an outage. CallerRunsPolicy is often described as a policy that never loses work, so people choose it for background tasks. But it moves work to whatever thread submitted it, and in a web service that thread belongs to the web server. Interviewers ask this to see whether we can follow a slowdown from one pool to the whole server and propose something better. In this answer, we will recap how Tomcat handles requests, follow the failure step by step, see why an event loop would suffer even more, and then look at two alternatives: rejecting and shedding the background work, and explicit backpressure with a bounded wait.

1A Quick Recap of Tomcat's Request Threads

Spring Boot's embedded Tomcat accepts connections and hands each request to a thread from its own pool. By default that pool has at most 200 threads (server.tomcat.threads.max). When all 200 are busy, Tomcat still accepts connections up to its connection limit, but their requests wait. Beyond that, new connections wait in the operating system's accept queue (server.tomcat.accept-count, 100 by default), and when that is full, clients see timeouts or refused connections.

So request threads are a shared, limited resource. Every endpoint, fast or slow, needs one for as long as its request runs. Anything that keeps request threads busy for longer reduces capacity for every endpoint at once.

2Following the Failure Step by Step

Here is a configuration like the one in the question. A controller saves an order and submits a background task, such as sending events to an analytics service, to a small bounded pool.

Java
@Bean
ThreadPoolTaskExecutor backgroundPool() {
ThreadPoolTaskExecutor ex = new ThreadPoolTaskExecutor();
ex.setCorePoolSize(10);
ex.setMaxPoolSize(10);
ex.setQueueCapacity(500);
ex.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // the problem
return ex;
}
@PostMapping("/orders")
Order create(@RequestBody OrderRequest req) {
Order o = orders.save(req); // 20 ms
backgroundPool.execute(() -> analytics.send(o)); // normally 30 ms on a pool thread
return o;
}
Step throughHow CallerRunsPolicy spreads the slowdown
ClientTomcat threadBackground poolAnalytics
POST /orders
execute(send event)
queue full: CallerRunsPolicy
send event on the request thread
5 s later
201 after 5 s
GET /products: no free thread, waits

7 messages in order. Play them, or step through them one at a time.

The rejected task borrows the request thread, so every endpoint loses capacity.

In normal times, analytics.send() takes 30 ms and ten pool threads easily keep up. Then the analytics service slows down and each call takes 5 seconds. Ten threads now finish two calls per second, the queue of 500 fills in a few seconds, and from that moment every rejected task runs on the request thread that called execute().

So a POST /orders that used to take 20 ms now takes 5 seconds, and its request thread is busy for all of that time. At 50 orders per second, within a few seconds all 200 Tomcat threads are inside analytics.send(). A GET /health or GET /products request that never touches analytics now has no thread to run on. It waits, then connections back up into the accept queue, and when that fills, the load balancer sees refused connections and marks the instance unhealthy. A slowdown in a non-critical background dependency has become a full outage.

3Why an Event Loop Makes It Worse

In a reactive stack such as Spring WebFlux on Netty, there are no 200 request threads. A few event loop threads, usually one per CPU core, each serve many connections by never blocking. If such a thread submits to a pool with CallerRunsPolicy and the pool is full, the event loop thread itself runs the 5-second task. Every connection assigned to that loop, often thousands of them, stops making progress for those 5 seconds. With four loops, four rejections are enough to freeze the whole server.

So the rule is general: CallerRunsPolicy is only safe when the submitting thread is one we are happy to slow down, such as a batch reader. Request threads and event loops are never such threads.

4Alternative 1: Reject and Shed the Background Work

The background task is not part of the answer the client is waiting for, so when there is no capacity for it, we should give it up quickly and in a visible way. We switch to AbortPolicy, catch the rejection, count it, and decide per task whether to drop it or to save it somewhere durable for later.

Java
ex.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
ex.setQueueCapacity(200);
@PostMapping("/orders")
Order create(@RequestBody OrderRequest req) {
Order o = orders.save(req);
try {
backgroundPool.execute(() -> analytics.send(o));
} catch (TaskRejectedException e) { // Spring's subclass of RejectedExecutionException
shedCounter.increment(); // alert when this rises
outbox.saveLater(o.id()); // or just drop it, if losing analytics is acceptable
}
return o; // still 20 ms, whatever analytics does
}

Notice what changed. The request thread now does at most a cheap insert or nothing at all, so POST /orders stays fast and other endpoints keep their threads. The analytics slowdown is still visible, through the rejection counter and an alert on it, but it stays contained. We also add a timeout and ideally a circuit breaker to analytics.send(), so the background threads themselves are not held for 5 seconds each.

If the background work must not be lost, the strongest form is the outbox pattern: write the event to a table in the same database transaction as the order, and let a separate worker send it. Then the web request never depends on the analytics service at all.

5Alternative 2: Explicit Backpressure With a Bounded Wait

Sometimes we do want callers to slow down, for example when the background work is part of the request's promise. Then we make that backpressure explicit and bounded, instead of letting the policy decide. A Semaphore, a counter of permits, limits how many tasks may be in the pool or queue, and the caller waits only a short time for a permit.

Java
Semaphore slots = new Semaphore(210); // 10 threads + 200 queued
void submit(Runnable task) {
if (!slots.tryAcquire(50, TimeUnit.MILLISECONDS)) { // wait at most 50 ms
throw new ServiceBusyException(); // mapped to 503 with Retry-After
}
try {
pool.execute(() -> { try { task.run(); } finally { slots.release(); } });
} catch (RejectedExecutionException e) {
slots.release();
throw new ServiceBusyException();
}
}

The difference from CallerRunsPolicy is that the request thread waits at most 50 ms and never runs the slow work itself. The worst case is a fast 503 for that one endpoint, while the rest of the server keeps working. Either way, we alert on rejections and queue depth, so the team learns about the slowdown from the dashboard rather than from refused connections.

6Follow-up questions

Is CallerRunsPolicy ever the right choice?

Yes, when the producer is a thread whose only job is to feed the pool, such as a batch job reading records from a file or a Kafka partition. Slowing that thread is exactly the backpressure we want, and no unrelated work depends on it.

Would virtual threads for Tomcat have prevented this?

They would remove the limit of 200 request threads, so unrelated requests would still get a thread. But each order request would still take 5 seconds, memory would grow with waiting requests, and the analytics service would receive even more load. The real fix is still to keep slow, optional work off the request path.

How would you detect this problem before an outage?

Alert on rejections from the background pool and on its queue depth, and watch Tomcat's busy thread count. A load test where the analytics stub is made slow would show the request threads filling up within seconds, which is the cheapest way to find it.

7Conclusion

In this answer, we followed a slowdown from a background pool to the whole web server. With CallerRunsPolicy, rejected tasks run on Tomcat request threads, those threads do the slow work, unrelated endpoints run out of threads and connections back up; on an event loop, a single rejection stalls every connection on that loop. The better design rejects with AbortPolicy and sheds or stores the background work, with a metric and an alert, and if backpressure is wanted, applies it explicitly with a short bounded wait and a fast error.

What to say in the interviewAbout 90 seconds aloud

Open with

The key is which thread runs a rejected task under CallerRunsPolicy: the thread that called execute, which here is a Tomcat request thread. When the downstream that the background tasks call slows down, the pool's threads stay busy, the bounded queue fills, and from then on every request that submits a task runs that slow task itself.

Then, if they want more

Tomcat has 200 request threads by default, so within seconds all of them are doing background work, and endpoints that have nothing to do with it, like health checks, cannot get a thread. Their connections wait, the accept queue fills, and the load balancer sees refused connections.

On WebFlux it is even worse, because an event loop thread that runs the task freezes every connection on that loop.

What I would do instead: switch to AbortPolicy, catch the rejection in the controller and shed the background work, either drop it if it is optional, like analytics, or write it to an outbox table so a worker sends it later.

I would add timeouts and a circuit breaker to the downstream call so pool threads are not held either, and alert on rejections and queue depth.

If we genuinely want callers to slow down, I would make that explicit, with a semaphore and a tryAcquire of maybe 50 milliseconds, then a fast 503 with Retry-After, so a request thread never runs the slow work itself.

About this answer

Last updated
12 November 2026
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.
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 web service submits background tasks to a bounded pool configured with...": https://scrivio-interview-library.netlify.app/java/executors/1d6d14cbf9/