当前位置:网站首页>线程的不同状态
线程的不同状态
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()方法,该线程借宿生命周期.
边栏推荐
- [LeetCode Daily Question] - 103. Zigzag Level Order Traversal of Binary Tree
- 工程师如何对待开源
- 垃圾回收器CMS和G1
- oracle query scan full table and walk index
- Fundamentals of Cryptography: X.690 and Corresponding BER CER DER Encodings
- Nanoprobes多组氨酸 (His-) 标签标记:重组蛋白检测方案
- Golang分布式应用之定时任务
- 永磁同步电机36问(二)——机械量与电物理量如何转化?
- Hash collisions and consistent hashing
- LeetCode Review Diary: 153. Find the Minimum Value in a Rotated Sort Array
猜你喜欢
随机推荐
Win Go development kit installation configuration, GoLand configuration
LeetCode Brushing Diary: 74. Searching 2D Matrix
软件测试 接口自动化测试 pytest框架封装 requests库 封装统一请求和多个基础路径处理 接口关联封装 测试用例写在yaml文件中 数据热加载(动态参数) 断言
使用docker安装mysql
60 Feature Engineering Operations: Using Custom Aggregate Functions【Favorites】
AOF重写
MySQL optimization strategy
使用DBeaver进行mysql数据备份与恢复
Personal blog system project test
Nanoprobes丨1-mercapto-(triethylene glycol) methyl ether functionalized gold nanoparticles
【LeetCode每日一题】——103.二叉树的锯齿形层序遍历
Nanoprobes Polyhistidine (His-) Tag: Recombinant Protein Detection Protocol
Install mysql using docker
『网易实习』周记(一)
Power button 1374. Generate each character string is an odd number
Project Background Technology Express
"NetEase Internship" Weekly Diary (1)
雇用WordPress开发人员:4个实用的方法
LeetCode刷题日记:34、 在排序数组中查找元素的第一个和最后一个位置
Pinduoduo leverages the consumer expo to promote the upgrading of domestic agricultural products brands and keep pace with international high-quality agricultural products