得到Thread Dump
通过jstack加上进程号即可得到thread dump
jstack -l [pid] > dump.txt
线程的状态和类型
得到的thread dump实际上是该进程下所有线程的情况列表,包括线程的名字、状态、类型等,比如:
"DEADLOCK_TEST-1" daemon prio=6 tid=0x000000000690f800 nid=0x1820 waiting for monitor entry [0x000000000805f000]
java.lang.Thread.State: BLOCKED (on object monitor)
at com.nbp.theplatform.threaddump.ThreadDeadLockState$DeadlockThread.goMonitorDeadlock(ThreadDeadLockState.java:197)
- waiting to lock <0x00000007d58f5e60> (a com.nbp.theplatform.threaddump.ThreadDeadLockState$Monitor)
at com.nbp.theplatform.threaddump.ThreadDeadLockState$DeadlockThread.monitorOurLock(ThreadDeadLockState.java:182)
- locked <0x00000007d58f5e48> (a com.nbp.theplatform.threaddump.ThreadDeadLockState$Monitor)
at com.nbp.theplatform.threaddump.ThreadDeadLockState$DeadlockThread.run(ThreadDeadLockState.java:135)
...
“BLOCKED_TEST pool-1-thread-1”是线程名
“daemon”表示当前是一个后台线程
“BLOCKED”表示当前线程是阻塞状态
“0x000000000690f800”是thread ID
最后面也是量最大的信息是调用栈
所有的线程状态
- NEW: 线程被创建单尚未运行
- RUNNABLE: 线程正在运行
- BLOCKED: 线程在等其他线程释放锁
- WAITING: 线程处于等待状态,通常是由于线程上调用了wait, join或park方法.
- TIMED_WAITING: 有超时的等待,通常是由于线程上调用了带超时的wait, join或park方法