当前位置:网站首页>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 .
边栏推荐
- [MySQL] basic use of explain and the function of each column
- Advanced skills of testers: a guide to the application of unit test reports
- Kubernetes create service access pod
- Treatment of insufficient space in the root partition of armbain system
- CKS CKA CKAD 将终端更改为远程桌面
- 工作中非常重要的测试策略,你大概没注意过吧
- Reprint CSDN article operation
- 死锁的处理策略—预防死锁、避免死锁、检测和解除死锁
- Summary of "performance testing" of software testing, novice will know the knowledge points on the road
- 正则系列之组和范围(Groups and Ranges)
猜你喜欢
![Happy number [fast and slow pointer of ring PROBLEMS]](/img/37/5c94b9b062a54067a50918f94e61ea.png)
Happy number [fast and slow pointer of ring PROBLEMS]

Digital currency: far-reaching innovation
![[image segmentation] 2021 segformer neurips](/img/2f/a8631cbe9a46419b8dbd5205e1f5b5.png)
[image segmentation] 2021 segformer neurips

rviz打开后如何显示实时2D地图

el-input文本域字数限制,超过显示变红并禁止输入

Explain ThreadLocal in detail

Unable to climb hill sort, directly insert sort

转--利用C语言中的setjmp和longjmp,来实现异常捕获和协程

转载csdn文章操作

轉載csdn文章操作
随机推荐
Unable to climb hill sort, directly insert sort
SAP ui5 application development tutorial 104 - multi select support for SAP ui5 table controls and how to use code to select multiple table row items at a time
思科考试--冗余网络
Explain the use of locksupport in detail
Cisco test -- the concept and configuration test of routing
Multi picture alert ~ comparison of Huawei ECs and Alibaba cloud ECS
Quantifiers of regular series
用JpaTransactionManager操作数据库事务
104. SAP ui5 table control supports multi select and how to select multiple table row items at a time with code
Tcpdump command usage details
Genicam gentl standard ver1.5 (4) Chapter 5 acquisition engine
Advanced skills of testers: a guide to the application of unit test reports
思科考试--路由的概念和配置考试
el-input文本域字数限制,超过显示变红并禁止输入
Istio、eBPF 和 RSocket Broker:深入研究服务网格
下班前几分钟,我弄清了v-model与.sync的区别
Cloud Vulnerability Global Database
使用 EMQX Cloud 实现物联网设备一机一密验证
毕业季,既是告别,也是新的开始
I graduated from college in 14 years and changed to software testing in 3 months. My monthly salary was 13.5k. At the age of 32, I finally found the right direction