当前位置:网站首页>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 .
边栏推荐
- Multi picture alert ~ comparison of Huawei ECs and Alibaba cloud ECS
- The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received
- YOGA27多维一体电脑,兼具出色外观与高端配置
- Jerry's burning of upper version materials requires [chapter]
- Cisco exam -- redundant network
- Istio、eBPF 和 RSocket Broker:深入研究服务网格
- 想请教一下,证券开户选择哪个证券比较好?手机开户是安全么?
- Happy number [fast and slow pointer of ring PROBLEMS]
- [daily training] 66 add one-tenth
- Deadlock handling strategies - prevent deadlock, avoid deadlock, detect and remove deadlock
猜你喜欢

SAP intelligent robot process automation (IRPA) solution sharing

Detailed explanation of twenty common software testing methods (the most complete in History)

思科--WAN 的概念考试外部工具

Turn -- use setjmp and longjmp in C language to realize exception capture and collaboration

Stimulate new kinetic energy and promote digital economy in multiple places

思科--高可用和高可靠网络考试

Groups and ranges of regular series

plain framework的实际应用和扩展

Réimpression de l'article csdn

Multiple smart pointers
随机推荐
Summary of "performance testing" of software testing, novice will know the knowledge points on the road
locust的使用
[image segmentation] 2021 segformer neurips
A few minutes before work, I found out V-model and The difference between sync
Electron学习(三)之简单交互操作
想请教一下,证券开户选择哪个证券比较好?手机开户是安全么?
每日刷题记录 (十)
若干互联网暴露面的收敛及处置建议
[kotlin third party] coil koltin collaboration picture loading library coil glide like picture loading third party
[MySQL] index creation, viewing and deletion
Single step debugging analysis of rxjs observable of operator
Genicam gentl standard ver1.5 (4) Chapter 5 acquisition engine
Origin2018 installation tutorial "recommended collection"
Kubernetes create service access pod
Detailed explanation of common configurations in redis configuration file [easy to understand]
半监督学习之数据增强
通过Go语言创建CA与签发证书
Digital currency: far-reaching innovation
思科--高可用和高可靠网络考试
Map container