Demo: diagnosing a deadlock from a thread dump
On This Lesson 3 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
read a thread dump and fix the cause.
Draft outline details
Step by step
- Run a Shop
transfer(from, to)that locks both accounts in argument order; fire opposite transfers concurrently. - The app hangs; take a dump with
jcmd <pid> Thread.print. - Find the "Found one Java-level deadlock" section; read which thread holds which lock and waits for which.
- Planned mistake: restart the app and call it solved. Fix: record the dump, identify the lock order, then fix it.
- Apply ordered locking (lower id first) and rerun the stress test; no hang.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.