Video in progress
The service "freezes" from time to time. You take a thread dump. What do you look for in it?
I take 3-5 dumps a few seconds apart and compare them: threads stuck in the same stack, threads in the BLOCKED state waiting on one lock, deadlocks the JVM detected, and pool threads that are all busy.
📖 Answer
One dump is a photograph, several are a film. Only across several dumps can you see that a thread has been standing in one place.
for i in 1 2 3 4 5; do jcmd $PID Thread.print > td-$i.txt; sleep 5; done
What I look at:
- Deadlock: the JVM writes it at the end of the dump itself:
Found one Java-level deadlock, with which thread holds which lock and which one it is waiting for. - BLOCKED:
waiting to lock <0x...>. I search for that address and find the thread that sayslocked <0x...>. Then I see what that thread is doing, often asynchronizedblock around slow I/O. - WAITING/TIMED_WAITING in large numbers: what are they waiting for?
HikariPool.getConnection(the DB pool is exhausted), orSocketInputStream.read(an external service isn't responding and there is no timeout). - If all the
http-nio-8080-exec-*threads are busy, the Tomcat pool is full and new requests are queued.
"http-nio-8080-exec-17" #63 daemon prio=5 ... waiting on condition
java.lang.Thread.State: TIMED_WAITING (parking)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:181)
Java 21 virtual threads don't show up in Thread.print. For them you use jcmd $PID Thread.dump_to_file -format=json threads.json.
Sign up to mark studied questions and save your progress.