当前位置:网站首页>One minute to understand the difference between synchronous, asynchronous, blocking and non blocking
One minute to understand the difference between synchronous, asynchronous, blocking and non blocking
2022-06-26 02:01:00 【Murong Tianyu】
I talked with brother Xu about the concurrency mechanism today , We have learned the difference between synchronous and asynchronous blocking and non blocking , Sum it up , Strengthen understanding , I don't say much nonsense , Just do it .
Raise questions
What's the difference between synchronous and asynchronous ?
What is the difference between blocking and non blocking ?
You can try to think about it in your mind , Have your own answer first , Then look down
.
.
.
.
.
.
Take a look at the answer
Synchronous and asynchronous are concerned with the way values are returned ,
Synchronization means that the service provider responds to the user after processing .
Asynchrony means that the service provider returns a value that has received the request first , Then the result will be returned after the actual processing , Or the caller requests to pull the result .
The focus of blocking and non blocking is the state of the caller
Blocking occurs when the server is processing , The state of the caller is doing nothing .
Instead of blocking, it is when the server handles , The caller does his own thing , Don't wait here , The caller queries the results by himself , Or the service provider notifies the caller when there is a result .
Advantages and disadvantages
Blocking
advantage : It can return data in time , There is no delay .
shortcoming , It takes time to wait .
Non blocking
advantage : Compare with blocking , Non blocking does not require waiting for task results , You can do other tasks , So it is better to support concurrency .
shortcoming : Unable to obtain the returned results in time . Because I only go back to ask at regular intervals , But the task may be completed within the time interval between the two asking actions , This leads to a reduction in the overall data throughput .
The combined scene
Let's take a look at the combined scenario through examples 
Synchronous blocking
Xiaoming goes to mingmingyuan to eat rice noodles , I ordered a rice noodle with minced meat , The waiter said it would take about half an hour , You have to wait . Then Xiao Ming did nothing and waited here , Wait until you're ready to go and find a seat .
BIO Is the synchronous blocking mode , Most of the methods we write are synchronous blocking .
Synchronous nonblocking
Or this one ,
When the master is sitting on rice noodles , Xiao Ming is not idle , He went to a seat , He brushed his cell phone for a while , But every time 10 minute , He went to see if the meal was ready .
NIO Synchronous non blocking mode ,
Asynchronous non-blocking
continue
Xiao Ming finished the rice noodles , The waiter gave Xiao Ming a number , Say rice noodles. I'll call you , Then Xiao Ming went to his seat to remember the words .
AIO Is asynchronous non blocking mode ,Callable And some with callback methods are in asynchronous non blocking mode .
Asynchronous blocking
This is a stupid way , Generally, no one will use it
边栏推荐
猜你喜欢

Show spirit chenzitong was invited to be the chief experience officer of the global finals of the sixth season perfect children's model

Pixel6 unlock bootloader

jenkins汉化及汉化无效解决方案

秀场精灵陈梓桐 受邀担任第六季完美童模全球总决赛首席体验官

CyCa children's physical etiquette Yueqing City training results assessment successfully concluded

Principle of voice wake-up

安装了Visual Studio 2013 Redistributable,mysql还是安装失败

Talking about interface test (I)

接口测试用例设计

Differences and functions of TOS cos DSCP
随机推荐
胰蛋白酶的化学性质及应用
热血男孩滕文泽 受邀担任第六季完美童模全球总决赛形象大使
高手常用的电脑快捷键
shell学习记录(二)
Two indicators for determining the value of points to the business
通俗易懂C語言關鍵字static
关于VS scanf出现‘scanf‘: This function or variable may be unsafe. Consider usi问题的解决方法
Redis7.0 installation steps
LeetCode 41 ~ 50
求n乘阶之和
清甜女孩李斯霞 受邀担任第六季完美童模全球总决赛小主持人
前置++,后置++与前置--与后置--(++a,a++与--a,a--)
Disruptor(一)Sequence
Talking about interface test (2)
Brief introduction to the usage of iloc in dataframe
GUN make (4) 规则的命令
分布式系统(二)分布式事务的理解
V4L2+QT视频优化策略
PTA class a simulated first bomb: 1132-1135
Application and chemical properties of elastase