Quick revision
The short answer
Thread exec-3 holds the PriceCache monitor while it reads from a socket inside refresh(), and the other 40 request threads are BLOCKED in get() waiting for that same lock, so the Tomcat pool is exhausted and the service stops answering. If the remote call has no timeout, the lock can be held indefinitely. The fix is never to hold a lock during network I/O: refresh in the background, build a new immutable snapshot, and publish it through a volatile reference so readers never lock, and set timeouts on the remote call. To confirm the diagnosis, we take two or three dumps a few seconds apart and check that the same thread still holds the lock.
What to remember
In this answer, we matched the lock address in the dump to see that exec-3 holds the PriceCache monitor during a socket read in refresh() while 40 request threads are BLOCKED in get(), which exhausts the pool. Without a timeout, the lock can be held indefinitely. We confirmed it with several dumps a few seconds apart, and fixed it by moving the refresh to the background, publishing an immutable snapshot through a volatile reference, and putting timeouts on the remote call.
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.
Thread exec-3 holds the PriceCache monitor while it reads from a socket inside refresh(), and the other 40 request threads are BLOCKED in get() waiting for that same lock, so the Tomcat pool is exhausted and the service stops answering. If the remote call has no timeout, the lock can be held indefinitely. The fix is never to hold a lock during network I/O: refresh in the background, build a new immutable snapshot, and publish it through a volatile reference so readers never lock, and set timeouts on the remote call. To confirm the diagnosis, we take two or three dumps a few seconds apart and check that the same thread still holds the lock.
Why this question is asked
Reading a thread dump is one of the most practical skills in Java production support. This excerpt shows a pattern that appears again and again: one slow operation inside a synchronized block turns into a complete outage, because every other thread queues behind it. Interviewers like it because the answer requires reading the dump carefully, connecting the lock addresses, and then proposing a fix that removes the cause, not just a bigger thread pool. In this answer, we will read the dump line by line, reproduce the code that produces it, explain why one slow call stops the whole service, confirm the diagnosis, and fix it with a snapshot and timeouts.
1A Quick Recap: Monitors and Thread States
Every Java object has a monitor, a lock that synchronized uses. When a thread enters a synchronized method or block, it acquires the monitor of the object; any other thread that tries to enter a synchronized block on the same object must wait until the first thread leaves. In a thread dump, a thread that is waiting to enter is in state BLOCKED (on object monitor), and its stack shows waiting to lock <address>. The thread that owns the monitor shows locked <address> in its stack, at the frame where it entered.
The address in angle brackets identifies the object. So the key move when reading a dump is to match the address in waiting to lock lines with the same address in a locked line. That tells us who is waiting for whom.
2Reading the Dump
The excerpt has two parts. Forty request threads, such as http-nio-8080-exec-12, are BLOCKED at PriceCache.get line 41, each waiting to lock <0x71a2b3c48>, a PriceCache object. One thread, exec-3, is RUNNABLE in SocketInputStream.socketRead0, a native method that reads from a network socket, called from PriceCache.refresh line 77, and further down its stack it shows locked <0x71a2b3c48>: the same object.
So exec-3 entered a synchronized refresh() on the cache, and while holding the lock it is waiting for bytes from a remote server. Notice that a thread blocked in a socket read is shown as RUNNABLE, because from the JVM's point of view it is executing native code. RUNNABLE does not mean it is using CPU. Every other request needs get(), get() is synchronized on the same object, and so every request thread is parked behind exec-3.
6 messages in order. Play them, or step through them one at a time.
While exec-3 waits on the network, the lock is held and all request threads queue on it.
3Reproducing the Code Behind It
The code that produces this dump usually looks innocent. Both methods are synchronized on the cache, and refresh() fetches fresh prices from a remote service when the data is old.
When the cache expires, the first request thread to arrive, exec-3, calls refresh() and makes the network call with the lock held. If the pricing service responds in 50 ms, nobody notices. If it is slow, or the connection hangs without a timeout, the lock is held for seconds or indefinitely, and every request queues behind it. With a Tomcat pool of 200 threads, once all of them are blocked, new connections wait in the accept queue and the service looks dead, although its CPU is idle.
4Confirming the Diagnosis With Several Dumps
A single dump is a snapshot. Maybe exec-3 was just unlucky at that instant and the lock changes hands every few milliseconds. To be sure, we take two or three dumps a few seconds apart and compare.
The same thread owns the lock in all three dumps, still inside the socket read, and the queue of blocked threads grows. That confirms a lock held during slow I/O. If the owner changed between dumps, we would be looking at heavy contention instead, which needs a different fix.
5The Fix: No Lock During I/O, Publish an Immutable Snapshot
The real problem is holding a lock while waiting on the network. We remove the lock from the read path entirely. Readers read a reference to an immutable map; a background task fetches new prices, builds a new map and swaps the reference. The volatile keyword makes sure that when the reference changes, every reader thread sees the new, fully built map.
Now a slow pricing service delays only the background refresh, never a request; requests keep getting the previous snapshot, which is usually far better than no answer. Map.copyOf makes the map immutable, so no reader can see it half built. Notice that the cache now starts empty, so we load it once at startup, before the service reports itself ready, so the first requests do not see missing prices. The second part of the fix is timeouts on the client itself, for example a connect timeout of 1 second and a read timeout of 2 seconds, so even the background thread cannot hang forever. If prices must be fresher than the schedule allows, a library cache such as Caffeine with refreshAfterWrite does the same thing: it serves the old value while one thread reloads.
6Why Not Just Add More Threads?
A bigger Tomcat pool only means more threads queue behind the same lock; the outage takes a little longer to start and uses more memory. A shorter lock or a ReentrantLock with tryLock would help, but it still couples request latency to the remote service. The general rule from this dump is worth stating in the interview: never do network or disk I/O while holding a lock that request threads need, and always put timeouts on remote calls.
7Follow-up questions
Why is exec-3 RUNNABLE if it is just waiting?
Because it is inside a native method, socketRead0, and the JVM cannot tell whether native code is computing or waiting. The thread state reflects the JVM's view, so threads blocked in socket reads show as RUNNABLE. The stack, not the state, tells us it is waiting on I/O.
Would virtual threads have avoided this outage?
Not by themselves. Virtual threads make blocked threads cheap, but they still wait for the same lock, so requests still stall. On JDK 21 to 23, a virtual thread doing blocking I/O inside synchronized also pins its carrier thread, which makes things worse; later releases removed most pinning for synchronized (check your version). The design fix is the same.
How would we detect this before customers do?
Monitor the Tomcat busy thread count and request queue time, alert when the pool stays near full, and use JFR's monitor blocked events, which record long waits for locks with the stack of the waiting thread and the lock class.
8Conclusion
In this answer, we matched the lock address in the dump to see that exec-3 holds the PriceCache monitor during a socket read in refresh() while 40 request threads are BLOCKED in get(), which exhausts the pool. Without a timeout, the lock can be held indefinitely. We confirmed it with several dumps a few seconds apart, and fixed it by moving the refresh to the background, publishing an immutable snapshot through a volatile reference, and putting timeouts on the remote call.
Open with
The key is the lock address. Forty request threads are BLOCKED in PriceCache.get, waiting to lock 0x71a2b3c48, which is the PriceCache object. And exec-3 shows locked on that same address, further down a stack that ends in socketRead0, called from PriceCache.refresh.
Then, if they want more
So exec-3 entered a synchronized refresh and is now waiting for a remote server while holding the lock. It shows RUNNABLE only because it's in native code; it isn't doing work.
Every request needs get, get is synchronized on the same object, so all the request threads queue behind exec-3, the Tomcat pool runs out, and the service looks dead while the CPU is idle. If that client has no read timeout, the lock can be held forever.
To confirm, I'd take two or three dumps five seconds apart and check that the same thread still owns the lock and the queue is growing. The fix is to never hold a lock during network I/O.
I'd make reads lock-free: a volatile reference to an immutable map, Map.copyOf, and a background task that fetches new prices, builds a fresh map and swaps the reference, keeping the old data if the refresh fails. And I'd put connect and read timeouts on the pricing client.
A bigger thread pool wouldn't help; more threads would just queue behind the same lock.
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.
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 "This thread dump excerpt is from a service that stopped responding. What is wrong and...": https://scrivio-interview-library.netlify.app/java/jvm-diagnostics/f5d760a5be/