Java Thread的6中状态图

状态图

Thread Map

六种状态之一

先来一波官方的解释
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.
退出

六种状态之二

先看图的左侧.是线程状态的主轴线.

Created with Raphaël 2.2.0 NEW RUNNABLE TERMINATED

再来看右侧

Created with Raphaël 2.2.0 BLOCKED WAITING TIME_WAITING
  • BLOCKDRUNNABLE之间的转换
获取了monitor锁
进入到被synchronized修饰的方法或者代码块
BLOCKED
RUNNABLE
  • WAITINGRUNNABLE之间的转换
Object.wait
Thread.join
LockSuper.park
Object.notify
Object.notifyAll
LockSuper.unpark
RUNNABLE
WAITING

-TIME_WAITINGRUNNABLE之间的转换

Thread.sleep
Object.wait
Thread.join
Waiting time coming
Object.notify
Object.notifyAll
RUNNABLE
TIME_WAITING

如何记忆

  • 左边三个是new runnable terminated;
  • 右边三个是block time_waiting waiting;
  • 右边三个和runnable之间的关系密切;
  • block是因为synchronized关键字
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值