当前位置:网站首页>Understanding threads
Understanding threads
2022-07-01 23:06:00 【InfoQ】
Recognize threads
State of thread
- NEW, New state : Threads are created , But the thread state when it is not started
- RUNNABLE, Ready state : Indicates the state that the thread can run , It may be running , Or waiting in line for the operating system to allocate CPU resources ;
- BLOCKED, Blocked thread state waiting for lock : Indicates a thread in a blocked state , Waiting for lock release , Like waiting for execution synchronized Code block or use synchronized Method of marking , But it has been executed by other threads , So I'm in a jam waiting .
- WAITING, Wait state : One thread is waiting for another thread to perform a specific action , This thread is waiting . For example, a thread calls Object.wait() , Then it is waiting for another thread to call Object.notify() or Object.notifyAll() Method , It is called waiting state .
- TIMED_WAITING, Timeout wait status : When waiting , A timeout will be set , When the waiting time exceeds the specified time , The state of the thread is called timeout waiting state . such as Object.wait(long timeout) and Thread.join(long timeout) Other methods , It will make it possible for the thread to enter this state .
- TERMINATED, Termination status : Indicates that the thread has completed execution .
public enum State {
NEW,
RUNNABLE,
BLOCKED,
WAITING,
TIMED_WAITING,
TERMINATED
}
Working mode of thread
- First create a thread , The thread is in NEW state .
- Specify the business methods that the thread needs to execute , The thread is in RUNNABLE state
- During thread execution , If you encounter a synchronized code block , And other threads execute one step first , Then the current thread will enter BLOCKED state . Wait until other threads finish executing synchronized code blocks , The current thread will continue to wait .
- If the code in the thread calls Object.wait() Methods or Thread.join() When the method is used , The thread will enter WAITING state , And when there is a set timeout , Then the thread will enter TIMED_WAITING Wait state . Until another thread executes notify() or notifyAll() Method , The current thread will be awakened , Continue code execution .
- Finally, the thread method execution is completed , Threads become TERMINATED state .
边栏推荐
- Metauniverse may become a new direction of Internet development
- Fiori applications are shared through the enhancement of adaptation project
- Use of locust
- 14年本科毕业,3个月转行软件测试月薪13.5k,32的岁我终于找对了方向
- Jerry's records are powered by Vbat with a power supply voltage of 4.2V [chapter]
- 力扣 710. 黑名单中的随机数
- window安装wsl(二)
- 激发新动能 多地发力数字经济
- 转--拿来即用:分享一个检查内存泄漏的小工具
- Rank ranking with MySQL 5.7
猜你喜欢

激发新动能 多地发力数字经济

91. (cesium chapter) cesium rocket launch simulation

Kubernetes create service access pod
![Jielizhi, production line assembly link [chapter]](/img/5f/9ea7fd3b93df1fd3ecbfc1b669c831.png)
Jielizhi, production line assembly link [chapter]

Reprint CSDN article operation

正则系列之组和范围(Groups and Ranges)
![Jielizhi Bluetooth headset quality control and production skills [chapter]](/img/3e/571d246d211a979e948dae1de56e93.png)
Jielizhi Bluetooth headset quality control and production skills [chapter]

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received

微信个人小商店一键开通助手小程序开发

leetcode - 287. Find duplicates
随机推荐
[MySQL] index creation, viewing and deletion
YOGA27多维一体电脑,兼具出色外观与高端配置
工作中非常重要的测试策略,你大概没注意过吧
Daily question brushing record (10)
有些能力,是工作中学不来的,看看这篇超过90%同行
CKS CKA CKAD 将终端更改为远程桌面
Detailed explanation of twenty common software testing methods (the most complete in History)
实在RPA:银行数字化,业务流程自动化“一小步”,贷款审核效率“一大步”
Data enhancement of semi supervised learning
Programming English vocabulary notebook
Cloud Vulnerability Global Database
半监督学习之数据增强
Explain the volatile keyword
[机缘参悟-35]:鬼谷子-飞箝篇-远程连接、远程控制与远程测试之术
[MySQL] basic use of explain and the function of each column
死锁的处理策略—预防死锁、避免死锁、检测和解除死锁
日本购物网站的网络乞丐功能
shell 流程控制
[daily training] 326 Power of 3
Use of locust