当前位置:网站首页>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 .
边栏推荐
- What are the benefits of third party acceptance testing? Recommended by professional third-party software testing institutions
- Advanced skills of testers: a guide to the application of unit test reports
- leetcode - 287. Find duplicates
- 认识线程
- What class loading mechanisms does the JVM have?
- AAAI22 | 结构标记和交互建模:用于图分类的“SLIM”网络
- Reprint CSDN article operation
- 玻璃马赛克
- Turn -- the underlying debugging principle of GDB is so simple
- Demo program implementation of QT version Huarui camera
猜你喜欢

Summary of "performance testing" of software testing, novice will know the knowledge points on the road
![Jielizhi, production line assembly link [chapter]](/img/84/73637de7ba334c5ac48895a7e82575.png)
Jielizhi, production line assembly link [chapter]

Multi picture alert ~ comparison of Huawei ECs and Alibaba cloud ECS
![Happy number [fast and slow pointer of ring PROBLEMS]](/img/37/5c94b9b062a54067a50918f94e61ea.png)
Happy number [fast and slow pointer of ring PROBLEMS]

Programming English vocabulary notebook
![Jerry's burning of upper version materials requires [chapter]](/img/65/fcd804e00dc08a2bd056e8e6493829.png)
Jerry's burning of upper version materials requires [chapter]

Explain the use of locksupport in detail

数字峰会人气火爆,城链科技引发新一轮商业变革

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

Quantifiers of regular series
随机推荐
Simple interactive operation of electron learning (III)
Cisco test -- the concept and configuration test of routing
【嵌入式系统课设】单个按键控制LED灯
SAP intelligent robot process automation (IRPA) solution sharing
Turn -- the underlying debugging principle of GDB is so simple
思科考试--冗余网络
马赛克后挡板是什么?
赵福全:短期解决保供,长期要打造安全、高效有韧性的供应链
Detailed explanation of common configurations in redis configuration file [easy to understand]
Turn -- bring it and use it: share a gadget for checking memory leaks
el-input文本域字数限制,超过显示变红并禁止输入
Appium automation test foundation - appium installation (I)
转--利用C语言中的setjmp和longjmp,来实现异常捕获和协程
Favorite transaction code management tool in SAP GUI
Jerry's question about long press boot detection [chapter]
Kubernetes create service access pod
数字货币:影响深远的创新
激发新动能 多地发力数字经济
Detailed explanation of twenty common software testing methods (the most complete in History)
Unable to climb hill sort, directly insert sort