Scrivio Interview library
ScenarioIntermediate6 min read · updated 12 November 2026

Under load, a Tomcat-based Spring Boot service rejects connections while CPU is only 40 percent. What Tomcat settings and causes would you investigate?

Low CPU with rejected connections usually means Tomcat's request threads are all busy waiting, not working: server.tomcat.threads.max (200 by default) caps concurrent requests, and once max-connections and the accept-count backlog are full, new connections are refused or time out. The usual cause is threads blocked on slow downstream calls or a small database pool, which a thread dump shows directly; the fix is to remove that bottleneck, add timeouts, and consider virtual threads.

Why this question is asked

This is a classic production incident. The dashboards show a service that is barely using its CPU, yet clients see connection refused or timeouts, and adding more replicas helps only briefly. Interviewers ask it because it tests whether we understand how Tomcat queues work, and whether we diagnose with evidence instead of raising every limit. In this answer, we will recap how Tomcat accepts and processes connections, see which settings limit each stage, find the real cause with a thread dump, and then fix it.

1How Tomcat Accepts and Processes Requests

Tomcat's NIO connector works in stages. The operating system completes TCP handshakes and holds them in a listen backlog. Tomcat's acceptor thread takes connections from that backlog and registers them with a poller, which watches many open connections for incoming data. When a request arrives on a connection, the poller hands it to a worker thread from the request thread pool, and that worker runs our filters and controllers until the response is written.

Each stage has a limit. server.tomcat.threads.max (default 200) is the number of worker threads, so at most 200 requests are processed at once. server.tomcat.max-connections (default 8192 for NIO) is how many connections Tomcat keeps open, including idle keep-alive ones. When that is reached, Tomcat stops accepting, and new connections wait in the operating system backlog, whose size is server.tomcat.accept-count (default 100). When the backlog is full, the operating system refuses or drops new connections.

Step throughA connection's path through Tomcat
  1. OS listen backlogaccept-count, default 100
  2. Acceptor and pollermax-connections, default 8192
  3. Free worker thread?threads.max, default 200
    YesRun the requestNoRequest waits in queue
  4. Run filters and controllerHolds the thread until done
  5. Write responseThread returns to pool

5 steps in order. Play them, or step through them one at a time.

When workers are all blocked, the queues behind them fill up until connections are refused.

2Why CPU Stays Low

CPU at 40 percent tells us the threads are not computing. A thread waiting for a socket read or for a database connection uses no CPU. So if all 200 worker threads are each waiting two seconds for a slow payment API, the service handles at most 100 requests per second, and the CPU sits idle. New requests queue, the queue fills, connections pile up to max-connections, then the backlog fills, and only then do clients see refusals.

This is Little's law in practice: concurrent requests equal throughput multiplied by time per request. With 200 threads and 2 seconds per request, throughput is capped at 100 per second. If a downstream call slows from 100 ms to 2 s, our capacity drops twenty times without any change on our side.

3Taking Thread Dumps to See Where Threads Wait

The fastest evidence is a thread dump taken while the problem is happening. We can use jcmd <pid> Thread.print, jstack, or the Actuator threaddump endpoint. Take three dumps a few seconds apart and look at the threads named http-nio-8080-exec-N.

Shell
$ jcmd 1 Thread.print | grep -A 12 'http-nio-8080-exec'
"http-nio-8080-exec-117" #142 daemon prio=5 WAITING (parking)
at jdk.internal.misc.Unsafe.park(Native Method)
at java.util.concurrent.locks.LockSupport.parkNanos(...)
at com.zaxxer.hikari.util.ConcurrentBag.borrow(ConcurrentBag.java:...)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:...)
at ...OrderRepository.findById(...)
"http-nio-8080-exec-118" #143 daemon prio=5 RUNNABLE
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at ...RestClient...exchange(...)
at ...PaymentClient.authorize(PaymentClient.java:41)

Notice the two patterns. Thread 117 is parked inside HikariPool.getConnection, which means it is waiting for a database connection; if most threads look like this, the pool (Hikari's default is 10 connections) is the bottleneck. Thread 118 is reading from a socket inside PaymentClient, which means it is waiting on a slow downstream. Counting how many of the 200 threads sit in each stack tells us where the time goes. Hikari's metrics, such as hikaricp.connections.pending, confirm the first case, and HTTP client timing metrics confirm the second.

4Fixing the Bottleneck

Raising threads.max to 800 is tempting but usually wrong. If the threads wait on a 10-connection pool, 800 threads just make a longer queue in front of the pool, use more memory and can overload the database. So we fix the cause.

If it is the database pool, we look at why connections are held long: slow queries, transactions that include remote calls, or a pool sized far below what the database can handle. We fix the queries, keep transactions short and size the pool with the database's limit in mind. If it is a slow downstream, we add connect and read timeouts (for example 1 s and 2 s) so a slow dependency cannot hold threads indefinitely, add a circuit breaker so we fail fast when it is down, and limit concurrent calls to it with a bulkhead so it cannot take all 200 threads.

Properties
# Timeouts on outbound calls (example values)
spring.http.client.connect-timeout=1s
spring.http.client.read-timeout=2s
# Hikari pool sized to the database's capacity
spring.datasource.hikari.maximum-pool-size=30
spring.datasource.hikari.connection-timeout=2000

Check your Boot version for the exact HTTP client property names; older versions configure timeouts on the RestTemplate or RestClient builder instead.

5Where Virtual Threads Fit

On Java 21 or later, spring.threads.virtual.enabled=true lets Tomcat run each request on a virtual thread, so waiting no longer uses up a fixed pool of 200. That removes the worker thread limit, but it does not remove the database pool or the slow downstream; requests would now queue there instead. So virtual threads are a good change after the bottleneck is understood and protected by timeouts and limits, not a substitute for finding it.

6Follow-up questions

What is the difference between max-connections and accept-count?

max-connections is how many connections Tomcat itself keeps open and watches, including idle keep-alive connections. accept-count is the size of the operating system queue for connections that Tomcat has not accepted yet because it is at max-connections. Once both are full, new connections are refused or time out.

Could keep-alive connections cause this on their own?

Yes, in some cases. If many clients hold idle keep-alive connections, they count toward max-connections. A low keepAliveTimeout or connection-timeout frees them sooner. But with the default 8192 this is less common than blocked worker threads.

How would you prevent this in the future?

Set timeouts on every outbound call, alert on Tomcat busy threads (tomcat.threads.busy) and Hikari pending connections rather than CPU alone, and load test with a slow dependency to see how the service behaves. Those metrics show the problem minutes before connections are refused.

7Conclusion

In this answer, we saw that Tomcat limits concurrent processing with threads.max and queues further connections up to max-connections and the accept-count backlog, so low CPU with refusals means worker threads are waiting. Thread dumps show where they wait, usually a database pool or a slow downstream. The fix is to remove that bottleneck, put timeouts and bulkheads on outbound calls, and only then consider virtual threads to lift the thread limit.

What to say in the interviewAbout 80 seconds aloud

Open with

Low CPU plus rejected connections tells me the request threads are waiting, not working. Tomcat processes at most server.tomcat.threads.max requests at once, 200 by default. Extra connections are held up to max-connections, 8192 for NIO, and beyond that they queue in the OS backlog sized by accept-count, 100 by default; when that is full, clients get refused or time out.

Then, if they want more

So I would take three thread dumps a few seconds apart, with jcmd or the Actuator endpoint, and look at the http-nio exec threads. If most are parked in HikariPool.getConnection, the database pool is the bottleneck, which Hikari's pending connections metric confirms. If most are in a socket read inside some client, a downstream is slow.

I would not just raise threads.max, because more threads only make a longer queue in front of the real bottleneck. Instead I would fix slow queries or long transactions and size the pool properly, and put connect and read timeouts, a circuit breaker and a bulkhead on downstream calls.

Once that is under control, virtual threads are worth considering, since they remove the 200-thread limit. And I would alert on busy threads and pool waits, not only on CPU.

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
Jakarta EE specifications
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 "Under load, a Tomcat-based Spring Boot service rejects connections while CPU is only 40...": https://scrivio-interview-library.netlify.app/java/servlets/8c437b5cf6/