当前位置: 首页 > news >正文

线程的6中状态

这个6中状态是Java Thread类中的枚举值中来的。

 public enum State {/*** Thread state for a thread which has not yet started.*/NEW,/*** Thread state for a runnable thread.  A thread in the runnable* state is executing in the Java virtual machine but it may* be waiting for other resources from the operating system* such as processor.*/RUNNABLE,/*** Thread state for a thread blocked waiting for a monitor lock.* A thread in the blocked state is waiting for a monitor lock* to enter a synchronized block/method or* reenter a synchronized block/method after calling* {@link Object#wait() Object.wait}.*/BLOCKED,/*** Thread state for a waiting thread.* A thread is in the waiting state due to calling one of the* following methods:* <ul>*   <li>{@link Object#wait() Object.wait} with no timeout</li>*   <li>{@link #join() Thread.join} with no timeout</li>*   <li>{@link LockSupport#park() LockSupport.park}</li>* </ul>** <p>A thread in the waiting state is waiting for another thread to* perform a particular action.** For example, a thread that has called <tt>Object.wait()</tt>* on an object is waiting for another thread to call* <tt>Object.notify()</tt> or <tt>Object.notifyAll()</tt> on* that object. A thread that has called <tt>Thread.join()</tt>* is waiting for a specified thread to terminate.*/WAITING,/*** Thread state for a waiting thread with a specified waiting time.* A thread is in the timed waiting state due to calling one of* the following methods with a specified positive waiting time:* <ul>*   <li>{@link #sleep Thread.sleep}</li>*   <li>{@link Object#wait(long) Object.wait} with timeout</li>*   <li>{@link #join(long) Thread.join} with timeout</li>*   <li>{@link LockSupport#parkNanos LockSupport.parkNanos}</li>*   <li>{@link LockSupport#parkUntil LockSupport.parkUntil}</li>* </ul>*/TIMED_WAITING,/*** Thread state for a terminated thread.* The thread has completed execution.*/TERMINATED;}

new : 就是创建了线程对象 但是还没有调用start 方法;

RUNNABLE: 线程正在执行任务;

BLOCKED: 阻塞状态,当前线程还没有抢到锁,就等在原地一直发呆的过程;
WAITING:当前线程拿到了CPU的执行权,但是由于某种原因还没开始执行自己的任务;
TIMED_WAITING: 调用了设置了等待时间的方法
TERMINATED: 任务执行完了;

相关文章:

  • win11 电脑睡眠功能失效了如何修复 win11 禁止鼠标唤醒
  • Linux的基本指令(4)
  • express框架搭建后台服务
  • 哈希一致性算法
  • 编程笔记 html5cssjs 028 HTML输入属性(2/2)
  • 系统安全及应用
  • 【Maven】下载及配置
  • Vagrant使用教程
  • 机器学习--ROC AUC
  • Axure骚操作:【制作可暂停与不可暂停进度加载条】
  • git 常用命令 提交commit
  • Python 工具 | pip 基本命令
  • leetcode算法题之递归--综合练习(二)
  • Go中interface != nil不一定不是nil
  • 【MySQL】MySQL 8+版本使用窗口函数可以减少一次连表操作(额外Avg函数和Using函数使用,Using关键字参考里自行了解)
  • [case10]使用RSQL实现端到端的动态查询
  • 【刷算法】从上往下打印二叉树
  • Centos6.8 使用rpm安装mysql5.7
  • HTML5新特性总结
  • iOS仿今日头条、壁纸应用、筛选分类、三方微博、颜色填充等源码
  • Python 反序列化安全问题(二)
  • Ruby 2.x 源代码分析:扩展 概述
  • SpiderData 2019年2月13日 DApp数据排行榜
  • SpringCloud集成分布式事务LCN (一)
  • SpriteKit 技巧之添加背景图片
  • uva 10370 Above Average
  • 从0搭建SpringBoot的HelloWorld -- Java版本
  • 码农张的Bug人生 - 见面之礼
  • 如何抓住下一波零售风口?看RPA玩转零售自动化
  • 微信开源mars源码分析1—上层samples分析
  • 06-01 点餐小程序前台界面搭建
  • SAP CRM里Lead通过工作流自动创建Opportunity的原理讲解 ...
  • 没有任何编程基础可以直接学习python语言吗?学会后能够做什么? ...
  • # 数据结构
  • #pragma multi_compile #pragma shader_feature
  • %check_box% in rails :coditions={:has_many , :through}
  • (Mac上)使用Python进行matplotlib 画图时,中文显示不出来
  • (ZT)出版业改革:该死的死,该生的生
  • (二)学习JVM —— 垃圾回收机制
  • (附源码)ssm旅游企业财务管理系统 毕业设计 102100
  • (原創) 如何解决make kernel时『clock skew detected』的warning? (OS) (Linux)
  • (最简单,详细,直接上手)uniapp/vue中英文多语言切换
  • ****Linux下Mysql的安装和配置
  • . Flume面试题
  • .cn根服务器被攻击之后
  • .NET CF命令行调试器MDbg入门(四) Attaching to Processes
  • .net on S60 ---- Net60 1.1发布 支持VS2008以及新的特性
  • .net 调用php,php 调用.net com组件 --
  • .NETCORE 开发登录接口MFA谷歌多因子身份验证
  • .stream().map与.stream().flatMap的使用
  • @Autowired标签与 @Resource标签 的区别
  • @德人合科技——天锐绿盾 | 图纸加密软件有哪些功能呢?
  • [ IO.File ] FileSystemWatcher
  • [20140403]查询是否产生日志
  • [BJDCTF2020]The mystery of ip