Java Thread的6中状态图
状态图
六种状态之一
先来一波官方的解释
A thread state. A thread can be in one of the following states:
- NEW
A thread that has not yet started is in this state.
创建了但是没有start
- RUNNABLE
A thread executing in the Java virtual machine is in this state.
可运行的(不是正在运行)
- BLOCKED
A thread that is blocked waiting for a monitor lock is in this state.
被阻塞等到锁(被synchronized 修饰)
- WAITING
A thread that is waiting indefinitely for another thread to perform a particular action is in this state.
等待另外一个线程的消息.
- TIMED_WAITING
A thread that is waiting for another thread to perform an action for up to a specified waiting time is in this state.
时间等待
- TERMINATED
A thread that has exited is in this state.
退出
六种状态之二
先看图的左侧.是线程状态的主轴线.
再来看右侧
-
BLOCKD
和RUNNABLE
之间的转换
-
WAITING
和RUNNABLE
之间的转换
-TIME_WAITING
和RUNNABLE
之间的转换
如何记忆
- 左边三个是
new
runnable
terminated
; - 右边三个是
block
time_waiting
waiting
; - 右边三个和
runnable
之间的关系密切; - block是因为synchronized关键字