当前位置:网站首页>线程的不同状态
线程的不同状态
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()方法,该线程借宿生命周期.
边栏推荐
- Remember a gorm transaction and debug to solve mysql deadlock
- Force buckle, 752-open turntable lock
- Safety (1)
- Fundamentals of Cryptography: X.690 and Corresponding BER CER DER Encodings
- The underlying data structure of Redis
- Power button 1374. Generate each character string is an odd number
- LeetCode brush diary: LCP 03. Machine's adventure
- Service discovery of kubernetes
- Handwritten Blog Platform ~ Day Two
- Oracle19c安装图文教程
猜你喜欢

The state status is displayed incorrectly after the openGauss switch

数据链路层的数据传输

Scheduled tasks for distributed applications in Golang

Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021: Interpretation

AI target segmentation capability for fast video cutout without green screen

Use baidu EasyDL implement factory workers smoking behavior recognition
![[ORB_SLAM2] void Frame::ComputeImageBounds(const cv::Mat & imLeft)](/img/ed/ffced88c9d23c20ccf380494051381.jpg)
[ORB_SLAM2] void Frame::ComputeImageBounds(const cv::Mat & imLeft)

菜刀webshell特征分析

一次SQL优化,数据库查询速度提升 60 倍

"NetEase Internship" Weekly Diary (2)
随机推荐
LeetCode 213. Robbery II (2022.08.01)
Use DBeaver for mysql data backup and recovery
AWR分析报告问题求助:SQL如何可以从哪几个方面优化?
MySQL8 download, start, configure, verify
C语言之插入字符简单练习
永磁同步电机36问(二)——机械量与电物理量如何转化?
力扣、752-打开转盘锁
swift项目,sqlcipher3 -> 4,无法打开旧版数据库有办法解决吗
LeetCode刷题日记: 33、搜索旋转排序数组
Pinduoduo leverages the consumer expo to promote the upgrading of domestic agricultural products brands and keep pace with international high-quality agricultural products
LeetCode Review Diary: 34. Find the first and last position of an element in a sorted array
数据链路层的数据传输
【 wheeled odometer 】
leetcode / anagram in string - some permutation of s1 string is a substring of s2
『网易实习』周记(一)
个人博客系统项目测试
[LeetCode Daily Question] - 103. Zigzag Level Order Traversal of Binary Tree
Hash collisions and consistent hashing
"NetEase Internship" Weekly Diary (3)
Can Youxuan database import wrongly be restored?