当前位置:网站首页>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 .
边栏推荐
- Happy number [fast and slow pointer of ring PROBLEMS]
- Business visualization - make your flowchart'run'up
- Force buckle 710 Random numbers in the blacklist
- Genicam gentl standard ver1.5 (4) Chapter 5 acquisition engine
- Deadlock handling strategies - prevent deadlock, avoid deadlock, detect and remove deadlock
- Jerry's question about long press boot detection [chapter]
- The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received
- locust的使用
- What are the benefits of third party acceptance testing? Recommended by professional third-party software testing institutions
- 众昂矿业:发展以氟化工为主的特色化工产业具有先天优势
猜你喜欢

Using emqx cloud to realize one machine one secret verification of IOT devices

Unable to climb hill sort, directly insert sort
![[MySQL] index classification](/img/73/fb9f28457b373ad35d2f6068387b47.png)
[MySQL] index classification

赵福全:短期解决保供,长期要打造安全、高效有韧性的供应链

MySQL -- deduction of index storage model

玻璃马赛克

Summary of "performance testing" of software testing, novice will know the knowledge points on the road

leetcode - 287. Find duplicates

Turn -- the underlying debugging principle of GDB is so simple

Use 3DMAX to make a chess piece
随机推荐
第三方验收测试有什么好处?专业第三方软件测试机构推荐
Use 3DMAX to make a chess piece
[daily training] 326 Power of 3
CKS CKA CKAD 将终端更改为远程桌面
104. SAP ui5 table control supports multi select and how to select multiple table row items at a time with code
openresty 负载均衡
Deadlock handling strategies - prevent deadlock, avoid deadlock, detect and remove deadlock
[kotlin third party] coil koltin collaboration picture loading library coil glide like picture loading third party
mysql ---- Oracle中的rownum转换成MySQL
Copy ‘XXXX‘ to effectively final temp variable
攻防演习防御体系构建之第三篇之建立实战化的安全体系
[QT widget] encapsulates a simple thread management class
轉載csdn文章操作
[MySQL] index creation, viewing and deletion
[MySQL] basic use of explain and the function of each column
半监督学习之数据增强
Jerry's question about long press boot detection [chapter]
Detailed explanation of common configurations in redis configuration file [easy to understand]
91. (cesium chapter) cesium rocket launch simulation
Detailed explanation of twenty common software testing methods (the most complete in History)