Video in progress
Requests are hanging, but CPU is low. How do you find the cause with a thread dump?
With jcmd <pid> Thread.print or /actuator/threaddump you take 2-3 dumps a few seconds apart and compare where the http-nio-*-exec-* threads are stuck. If many threads are WAITING or TIMED_WAITING in the same place, that resource is the bottleneck.
📖 Answer
Low CPU with hung requests means the threads aren't working, they're waiting for something. The dump shows exactly that.
jcmd 4211 Thread.print > dump1.txt; sleep 5; jcmd 4211 Thread.print > dump2.txt
grep -c 'http-nio-8080-exec' dump1.txt
The usual pictures in a dump:
| At the top of the stack | Likely cause |
|---|---|
HikariPool.getConnection |
the pool is exhausted: a long transaction, a connection leak, REQUIRES_NEW |
SocketInputStream.read + HTTP client classes |
an external service isn't responding, no timeout |
PgStream.receive / JDBC executeQuery |
a lock in the database or a slow query |
ReentrantLock.lock / synchronized (BLOCKED) |
a lock inside the application: someone is holding it |
Unsafe.park + LinkedBlockingQueue.take |
an idle thread: that's normal |
If the same thread is in the same place in both dumps, it's really stuck. For BLOCKED, the dump says "waiting to lock <0x...>"; you look for the thread that holds that address as "locked <0x...>". The JVM finds a classic deadlock itself and writes "Found one Java-level deadlock" at the end of the dump.
The next steps depend on the cause: for Hikari, turn on leak-detection-threshold and look at the pool metrics; put timeouts on external calls; on the database side, check pg_stat_activity and pg_locks.
If virtual threads are used, they may not show up in a plain dump; you need jcmd <pid> Thread.dump_to_file -format=json dump.json.
Sign up to mark studied questions and save your progress.