JDK 定义了 6 种:
start()
。jstack 输出的线程 dump,会显示更细粒度的状态:
RUNNABLE
"main" #1 prio=5 os_prio=31 tid=0x... RUNNABLE
BLOCKED (on object monitor)
- waiting to lock <0x00000000> (a java.lang.Object)
WAITING (on object monitor)
- waiting on <0x00000000> (a java.lang.Object)
TIMED_WAITING (sleeping)
TIMED_WAITING (parking)
TIMED_WAITING (on object monitor)
NATIVE (JNI calls)
TERMINATED
Java Thread.State | jstack 可能看到的状态 |
---|---|
NEW | 不会出现在 jstack(没 start() 不会 dump 出来) |
RUNNABLE | RUNNABLE |
BLOCKED | BLOCKED (on object monitor) |
WAITING | WAITING (on object monitor) / WAITING (parking) |
TIMED_WAITING | TIMED_WAITING (sleeping / parking / on object monitor) |
TERMINATED | 一般不显示(线程已消亡) |