当前位置:网站首页>线程的不同状态
线程的不同状态
2022-08-02 02:18:00 【月半的人】
线程在一定情况下,状态会发生变化.线程一共有以下几种状态.
1.新建状态(New):新创建了一个线程对象
2.就绪状态(Runnable):线程创建后,其他线程调用了该对象的start()方法.该状态的线程位于"可运行线程池"中,变得可运行,只等待获取CPU的使用权.即在就绪状态的进程除CPU之外,其他的运行所需资源都已经全部可获得.
3.运行状态(Running):就绪状态的线程获取了CPU,执行程序代码
4.阻塞状态(Blocked):阻塞状态是线程因为某种原因放弃使用CPU使用权,暂时停止运行,直到线程进入就绪状态,才有机会转到运行状态.
阻塞的情况分三种
(1).等待阻塞:运行的线程执行wait()方法,该线程会释放占用的所有资源,JVM会吧该线程放入"等待池"中.进入这个状态后,是不能自动唤醒的,必须依靠其他线程调用notify()或notifyAll()方法才能被唤醒.
(2)同步阻塞:运行的线程在获取对象同步锁时,若该同步锁被别的线程占用,则jvm会把该线程放入"锁池"中
(3)其他阻塞:运行的线程执行sleep()或join()方法,或者发出来I/O请求时,JVM会把该线程置为阻塞状态.当sleep()状态超时,join() 等待线程终止或者超时,或者I/O处理完毕时,线程重新转入就绪状态.
5.死亡中状态(Dead):线程执行完了或者因为异常退出了run()方法,该线程借宿生命周期.
边栏推荐
- Good News | AR opens a new model for the textile industry, and ALVA Systems wins another award!
- NIO's Sword
- Electronic Manufacturing Warehouse Barcode Management System Solution
- Check if IP or port is blocked
- Coding Experience Talk
- 拼多多借力消博会推动国内农产品品牌升级 看齐国际精品农货
- Redis for distributed applications in Golang
- What to study after the PMP exam?The soft exam ahead is waiting for you~
- 软件测试 接口自动化测试 pytest框架封装 requests库 封装统一请求和多个基础路径处理 接口关联封装 测试用例写在yaml文件中 数据热加载(动态参数) 断言
- Analysis of volatile principle
猜你喜欢
Project Background Technology Express
From 2023 onwards, these regions will be able to obtain a certificate with a score lower than 45 in the soft examination.
永磁同步电机36问(三)——SVPWM代码实现
Win Go development kit installation configuration, GoLand configuration
Outsourcing worked for three years, it was abolished...
『网易实习』周记(一)
[ORB_SLAM2] void Frame::ComputeImageBounds(const cv::Mat & imLeft)
MySQL optimization strategy
The Paddle Open Source Community Quarterly Report is here, everything you want to know is here
BioVendor Human Club Cellular Protein (CC16) Elisa Kit Research Fields
随机推荐
2022年NPDP考完多久出成绩?怎么查询?
工程师如何对待开源
2023年起,这些地区软考成绩低于45分也能拿证
AI目标分割能力,无需绿幕即可实现快速视频抠图
[Server data recovery] Data recovery case of server Raid5 array mdisk disk offline
PHP live source code to achieve simple barrage effect related code
Can Youxuan database import wrongly be restored?
The state status is displayed incorrectly after the openGauss switch
Analysis of the status quo of digital transformation of manufacturing enterprises
Redis 底层的数据结构
Install mysql using docker
Constructor instance method inheritance of typescript37-class (extends)
【 wheeled odometer 】
AntPathMatcher uses
Check if IP or port is blocked
2022 Henan Youth Training League Game (3)
一次SQL优化,数据库查询速度提升 60 倍
Redis Subscription and Redis Stream
密码学的基础:X.690和对应的BER CER DER编码
MySQL optimization strategy