当前位置:网站首页>线程的不同状态
线程的不同状态
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 Brushing Diary: 74. Searching 2D Matrix
- Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021: Interpretation
- openGauss切换后state状态显示不对
- Nanoprobes Polyhistidine (His-) Tag: Recombinant Protein Detection Protocol
- LeetCode Review Diary: 34. Find the first and last position of an element in a sorted array
- 2022-08-01 安装mysql监控工具phhMyAdmin
- Ask God to answer, how should this kind of sql be written?
- Nanoprobes免疫测定丨FluoroNanogold试剂免疫染色方案
- 2022年NPDP考完多久出成绩?怎么查询?
- Fundamentals of Cryptography: X.690 and Corresponding BER CER DER Encodings
猜你喜欢

2022-08-01 mysql/stoonedb slow SQL-Q18 analysis

MySQL8 download, start, configure, verify

The principle and code implementation of intelligent follower robot in the actual combat of innovative projects

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

The first time I wrote a programming interview question for Niu Ke: input a string and return the letter with the most occurrences of the string

2022-07-30 mysql8执行慢SQL-Q17分析

MySQL optimization strategy

A good book for newcomers to the workplace

Chopper webshell feature analysis

雇用WordPress开发人员:4个实用的方法
随机推荐
leetcode / anagram in string - some permutation of s1 string is a substring of s2
2022-07-30 mysql8执行慢SQL-Q17分析
【 wheeled odometer 】
Handwritten Blog Platform ~ Day Two
FOFAHUB usage test
The state status is displayed incorrectly after the openGauss switch
How to adjust the cross cursor too small, CAD dream drawing calculation skills
Analysis of the status quo of digital transformation of manufacturing enterprises
LeetCode刷题日记: 33、搜索旋转排序数组
PHP live source code to achieve simple barrage effect related code
永磁同步电机36问(二)——机械量与电物理量如何转化?
Centos7 install postgresql and enable remote access
nacos启动报错,已配置数据库,单机启动
The failure to create a role in Dahua Westward Journey has been solved
Golang分布式应用之定时任务
ALCCIKERS Shane 20191114
[Unity entry plan] 2D Game Kit: A preliminary understanding of the composition of 2D games
libcurl访问url保存为文件的简单示例
Nanoprobes Polyhistidine (His-) Tag: Recombinant Protein Detection Protocol
Force buckle, 752-open turntable lock