当前位置:网站首页>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 .
边栏推荐
- Flink SQL command line connection yarn
- The median salary of TSMC's global employees is about 460000, and the CEO is about 8.99 million; Apple raised the price of iPhone in Japan; VIM 9.0 release | geek headlines
- 实在RPA:银行数字化,业务流程自动化“一小步”,贷款审核效率“一大步”
- 正则系列之组和范围(Groups and Ranges)
- 思科考试--路由的概念和配置考试
- Tcpdump command usage details
- 日本购物网站的网络乞丐功能
- 使用3DMax制作一个象棋棋子
- Turn -- the underlying debugging principle of GDB is so simple
- Map container
猜你喜欢
正则系列之量词(Quantifiers)
91. (cesium chapter) cesium rocket launch simulation
rviz打开后如何显示实时2D地图
Advanced skills of testers: a guide to the application of unit test reports
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received
Multi picture alert ~ comparison of Huawei ECs and Alibaba cloud ECS
AAAI22 | 结构标记和交互建模:用于图分类的“SLIM”网络
Introduction and use of plantuml
Fiori applications are shared through the enhancement of adaptation project
shell 流程控制
随机推荐
CKS CKA CKAD 将终端更改为远程桌面
MySQL -- index of MyISAM storage engine
URL 介绍
Réimpression de l'article csdn
数字货币:影响深远的创新
转--深入LUA脚本语言,让你彻底明白调试原理
赵福全:短期解决保供,长期要打造安全、高效有韧性的供应链
SAP intelligent robot process automation (IRPA) solution sharing
Detailed explanation of twenty common software testing methods (the most complete in History)
Data enhancement of semi supervised learning
What are the benefits of third party acceptance testing? Recommended by professional third-party software testing institutions
Cutefishos system~
[MySQL] index classification
Single step debugging analysis of rxjs observable of operator
"Trust machine" empowers development
Preparation of functional test report
通过Go语言创建CA与签发证书
业务可视化-让你的流程图'Run'起来
认识线程
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received