当前位置:网站首页>[concurrent programming] collaboration between threads
[concurrent programming] collaboration between threads
2022-07-03 08:37:00 【keeper42】
2022.02.09
Collaboration between threads
polling : It is difficult to guarantee timeliness , Resources are expensive ,
Waiting and notifying
wait() Method on object
notify/notifyAll Method on object
The standard paradigm for waiting and notification
Waiting party :
- Get the lock of the object ;
- In the cycle, judge whether the conditions are satisfied , Not satisfied with call wait Method ,
- Conditions meet to execute business logic
The informer said
- Get the lock of the object ;
- Change the conditions
- Notify all threads waiting on the object
notify and notifyAll Who should I use ?
Should be used as much as possible notifyAll, Use notify Because there may be signal loss
Wait timeout mode implements a connection pool
hypothesis The waiting time is T, current time now+T After that, it's time-out
long overtime = now+T;
long remain = T;// The duration of the wait
while(result Not meeting the conditions && remain>0){
wait(remain);
remain = overtime – now;// Wait for the remaining duration
}
return result;join() Method
Threads A, Thread executed B Of join Method , Threads A You have to wait B When the execution is complete , Threads A To continue your work
call yield() 、sleep()、wait()、notify() What are the effects of methods such as ?
yield()\sleep() Does not release the lock , Just get out of the way cpu The enforcement of
Thread executing yield() in the future , The lock held is not released
sleep() When the method is called , The lock held is not released
Before the transfer method , You have to hold the lock . Called wait() After method , The lock will be released , When wait When the method returns , The thread will hold the lock again
Before the transfer method , You have to hold the lock , call notify() The method itself does not release the lock
边栏推荐
- Jupyter remote server configuration and server startup
- animation
- Mysql容器化(1)Docker安装MySQL
- Campus lost and found platform based on SSM, source code, database script, project import and operation video tutorial, Thesis Writing Tutorial
- 简易入手《SOM神经网络》的本质与原理
- Mall management system of database application technology course design
- [rust notes] 09- special types and generics
- [concurrent programming] Table hopping and blocking queue
- Introduction to Base64 coding
- Development material set
猜你喜欢
![P1596 [USACO10OCT]Lake Counting S](/img/a7/07a84c93ee476788d9443c0add808b.png)
P1596 [USACO10OCT]Lake Counting S

GIS实战应用案例100篇(七十八)-多规合一数据库设计及数据入库

Gradle's method of dynamically modifying APK package name

Dealing with duplicate data in Excel with xlwings

分配异常的servlet

Unity editor expansion - controls, layouts

Chocolate installation

Markdown learning

Unity learning notes

Osgearth target selection
随机推荐
【云原生】微服务之Feign的介绍与使用
Swagger document configuration
Exe file running window embedding QT window
UE4 plug in development
Downward compatibility and upward compatibility
[rust notes] 11 practical features
图像处理8-CNN图像分类
梯度下降法求解BP神经网络的简单Demo
单调栈-84. 柱状图中最大的矩形
Message queue for interprocess communication
Graphics_ Games101/202 learning notes
Redis的数据结构
Redis cluster series 4
Markdown learning
请求参数的发送和接收
Jupyter remote server configuration and server startup
matlab神經網絡所有傳遞函數(激活函數)公式詳解
[RPC] RPC remote procedure call
[rust notes] 05 error handling
Location of package cache downloaded by unity packagemanager