Threads Total: 76, NEW: 0, RUNNABLE: 19, BLOCKED: 999, WAITING: 18, TIMED_WAITING: 15, TERMINATED: 0, Internal threads: 10 ID NAME GROUP PRIORIT STATE %CPU DELTA_T TIME INTERRUP DAEMON 88 sentinel-time-tick-threa main 5 TIMED_W 3.14 0.006 0:3.618 false true 118 arthas-command-execute system 5 RUNNABL 1.43 0.002 0:0.014 false true -1 C1 CompilerThread2 - -1 - 0.16 0.000 0:3.077 false true -1 VM Periodic Task Thread - -1 - 0.06 0.000 0:0.078 false true 2 Reference Handler system 10 WAITING 0.0 0.000 0:0.017 false true 3 Finalizer system 8 WAITING 0.0 0.000 0:0.011 false true
2,执行“thread -b”命令,找出当前阻塞其他线程的线程,即造成死锁的罪魁祸首
1
thread -b
命令效果:
1 2 3 4 5 6
"Thread-39" Id=93 BLOCKED on java.lang.Object@1820d666 owned by "Thread-38" Id=92 at cn.soilove.expro.controller.TestController.lambda$hb$1(TestController.java:43) - blocked on java.lang.Object@1820d666 - locked java.lang.Object@29064ce5 <---- but blocks 7 other threads! at cn.soilove.expro.controller.TestController$$Lambda$1407/395258860.run(Unknown Source) at java.lang.Thread.run(Thread.java:748)
注:上面这个命令直接输出了 造成死锁的线程ID,和具体的代码位置,以及当前线程一共阻塞的线程数量:“<—- but blocks 7 other threads!“。是不是很优秀?现在,我们只需要去修改掉这的代码问题即可。