Scrivio Interview library
DebuggingIntermediate7 min read · updated 12 November 2026

A thread dump of a slow service shows 300 threads in state RUNNABLE with the top frame in a socket read method, yet CPU usage is low. What does this mean and what would you check?

A platform thread blocked inside a native socket read still reports RUNNABLE, because the JVM only knows it is executing native code, not that the operating system has put it to sleep waiting for data. So 300 RUNNABLE threads in socket reads with low CPU means 300 threads waiting on remote peers, not computing. Next I would read the stack frames above the socket read to see which client and downstream they belong to, such as an HTTP client or a JDBC driver, check whether read timeouts are missing or very long so stalled connections can hang threads indefinitely, and then set connect and read timeouts and add circuit breaking.

Why this question is asked

Thread dumps are the first tool we reach for when a Java service is slow, and they can mislead us. A dump showing hundreds of RUNNABLE threads looks like a CPU-bound service working hard, but the CPU graph says otherwise. Interviewers ask this scenario because the contradiction is real and common in production, and resolving it requires knowing what RUNNABLE actually means and how blocking I/O works underneath. In this answer, we will recap the state, explain why waiting threads look runnable, read the stack to find the culprit, check timeouts, and fix the service with timeouts and circuit breaking.

1A Quick Recap: RUNNABLE Is a JVM State

Thread.State has six values, and RUNNABLE is the one for a thread that is running or ready to run. It is defined from the JVM's point of view, not the operating system's. The JVM tracks when a thread waits on things it manages, such as monitors, Object.wait or LockSupport.park, and reports BLOCKED or WAITING for those.

A blocking socket read is different. The thread calls into native code, which makes a system call such as read or recv, and the operating system puts the thread to sleep until data arrives. The JVM does not see that sleep. As far as it knows, the thread is executing a native method, so it reports RUNNABLE.

Text
"http-nio-8080-exec-117" #245 daemon prio=5 os_prio=31 tid=0x... nid=0x... runnable
java.lang.Thread.State: RUNNABLE
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:47)
at sun.nio.ch.NioSocketImpl.tryRead(NioSocketImpl.java:...)
at sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:...)
...
at org.apache.hc.core5.http.impl.io.SessionInputBufferImpl.fillBuffer(...)
at org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute(...)
at com.example.inventory.InventoryClient.stock(InventoryClient.java:58)
at com.example.checkout.CheckoutService.place(CheckoutService.java:112)

The exact JDK frame names differ between versions, so check your version, but the shape is always the same: a native read at the top, a client library in the middle, and our own code below it.

2What Low CPU Tells Us

If 300 threads were really computing, a machine with 8 cores would be at 100 percent CPU and most threads would be waiting for a core. Low CPU with 300 RUNNABLE threads in socket reads can only mean that most of them are asleep in the kernel, waiting for bytes from the other end of their connections.

That changes the investigation completely. The service is not slow because it is doing too much work; it is slow because its threads are stuck waiting on something remote, and new requests either queue for a free thread or are rejected. The bottleneck is a downstream service, a database, or the network path to them. Per-thread CPU from top -H, or a JFR recording, confirms it: these threads show close to zero CPU time between two dumps taken a few seconds apart.

Step throughReading RUNNABLE threads in a dump
  1. Many threads RUNNABLE in socket read
  2. Is CPU high?
    YesLook for hot computation elsewhereNoThreads are waiting on remote peers
  3. Group by frames above the readHTTP client, JDBC driver, Redis, ...
  4. Identify the downstreamhost and pool from the client frames and config
  5. Read timeout set and sensible?
    YesInvestigate the downstream's latencyNoAdd connect and read timeouts
  6. Add circuit breaking and bulkheadsfail fast when the downstream is unhealthy

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

3Finding Which Downstream They Belong To

The frames above the socket read name the client. Apache HttpClient, OkHttp, Netty or the JDK HttpClient frames point to an HTTP call; frames from a JDBC driver, such as org.postgresql or com.mysql, point to the database; Lettuce or Jedis point to Redis. The frames below the client show which of our methods made the call, which usually identifies the service, like InventoryClient.stock in the dump above.

With 300 threads, we do not read them one by one. We group the dump by the first application frame, with a small script or a tool such as fastthread or a JFR thread view, and count. A typical result is that 280 threads are in InventoryClient and 20 are elsewhere, which points straight at the inventory service. Its own latency metrics, and the client's connection pool metrics, then show whether it is slow, overloaded or not responding at all on some connections.

4Checking the Timeouts

A stalled connection, where the other side stops sending without closing, for example after a network partition or a crashed load balancer node, leaves a read waiting until a timeout fires. If there is no read timeout, which is the default for a plain java.net.Socket and for some clients, the thread can wait for a very long time, sometimes until the operating system's TCP keepalive gives up after hours. Every such thread is lost to the service.

So we check each client's configuration: the connect timeout, how long to wait to establish a connection; the read or socket timeout, how long to wait for the next bytes; the timeout to obtain a connection from the client's pool; and, where the client supports it, an overall response timeout. For JDBC, that means the driver's socket timeout and the statement or query timeout. Very long values, like 5 minutes for a call whose p99 is 80 milliseconds, are as bad as none.

5The Fix: Timeouts and Circuit Breaking

Every remote call gets explicit timeouts sized from the downstream's real latency, typically a small multiple of its p99, and below our own callers' deadline.

Java
RequestConfig config = RequestConfig.custom()
.setConnectionRequestTimeout(Timeout.ofMilliseconds(200)) // wait for a pooled connection
.setResponseTimeout(Timeout.ofMilliseconds(800)) // wait for the response bytes
.build();
ConnectionConfig conn = ConnectionConfig.custom()
.setConnectTimeout(Timeout.ofMilliseconds(300))
.setSocketTimeout(Timeout.ofMilliseconds(800))
.build();
// Apache HttpClient 5 style; method names differ by client and version
CircuitBreaker breaker = CircuitBreaker.ofDefaults("inventory"); // Resilience4j
Supplier<Stock> call = CircuitBreaker.decorateSupplier(breaker, () -> inventory.stock(sku));
// when calls keep failing or timing out, the breaker opens and fails fast for a while

Timeouts cap how long one call can hold a thread. A circuit breaker, for example from Resilience4j, watches the failure and slow-call rate and, once it crosses a threshold, opens: further calls fail immediately without touching the network for a cooling-off period, then a few trial calls test whether the downstream has recovered. Together with a bulkhead, a limit on how many threads may call one downstream at a time, this stops one sick dependency from consuming all 300 threads and taking down endpoints that do not even use it.

After the change we verify the effect: under the same downstream slowdown, the thread dump should show at most the bulkhead's number of threads in that client, and the service's other endpoints should keep their normal latency.

6Follow-up questions

Would virtual threads solve this?

They would make waiting much cheaper, since a virtual thread blocked on a socket parks and frees its carrier, so we could have thousands waiting. But without timeouts, those requests still hang, and a slow downstream still makes users wait and can be overwhelmed by even more concurrent calls. Timeouts and circuit breakers are still required.

How do you tell a stalled connection from a slow downstream?

Take two or three dumps a few seconds apart. Threads that are stuck in the same read with no progress for minutes suggest stalled connections; threads that change between dumps suggest a slow but working downstream. Socket statistics from ss or netstat, such as connections with empty receive queues, help too.

7Conclusion

In this answer, we saw that platform threads blocked in native socket reads report RUNNABLE because the JVM cannot see that the operating system is making them wait, so many such threads with low CPU means the service is waiting on remote peers rather than computing. We used the stack frames above the read to identify the client and downstream, checked for missing or very long read timeouts that let threads hang on stalled connections, and fixed the service with explicit connect, read and pool timeouts plus circuit breaking and bulkheads.

What to say in the interviewAbout 100 seconds aloud

Open with

RUNNABLE in a thread dump doesn't mean the thread is using CPU. It's the JVM's view: when a platform thread does a blocking socket read, it goes into native code and the OS puts it to sleep waiting for data, but the JVM just sees a native method executing, so it reports RUNNABLE.

Then, if they want more

Combined with low CPU, 300 threads like that means they're all waiting on remote peers, not computing. The service is slow because its threads are stuck, and new requests queue behind them.

Next I'd look at the frames above the socket read to see which client they belong to, HTTP client, JDBC driver, Redis client, and the first application frame tells me which downstream. I'd group the dump by that frame; usually one dependency accounts for most threads. Then I'd check the timeouts on that client.

Often the read timeout is missing or huge, so when a connection stalls, say after a network problem, the thread waits for a very long time and never comes back to the pool. Two dumps a few seconds apart help tell stalled connections from a merely slow downstream.

The fix is explicit timeouts on every remote call: connect timeout, read or response timeout sized from the downstream's real latency, and a timeout for getting a connection from the pool.

Then I'd add a circuit breaker, for example with Resilience4j, so when the downstream keeps failing we fail fast instead of tying up threads, and a bulkhead to cap how many threads can wait on that one dependency.

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 thread dump of a slow service shows 300 threads in state RUNNABLE with the top frame...": https://scrivio-interview-library.netlify.app/java/threads/b869cdec99/