12-Java中线程的状态类型
Java中线程的状态类型
线程的状态类型
源码作者的原注释关于线程内部类
State
描述了线程的六个状态
- 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.
②、RUNNABLE
- 在Java虚拟机中执行的线程处于这种状态
- 源码中的注释
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.
④、WATING
- 无限期等待另一个线程执行特定操作的线程处于此状态
- 源码中的注释
A thread that is waiting indefinitely for another thread to perform a particular action is in this state.
⑤、TIMED_WATING
-
一个线程等待另一个线程执行操作,在指定的等待时间内处于此状态
-
源码中的注释
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.
小结
- 可以用一个枚举类来说明线程的这几个状态
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?