当前位置:网站首页>How to understand the difference between BIO, NIO, and AIO
How to understand the difference between BIO, NIO, and AIO
2022-08-10 09:20:00 【Huangnichuan water monkey】
1. Synchronous blocking I/O (BIO):
Synchronous blocking I/O, the server implementation mode is one connection and one thread, that is, when the client has a connection request, the server needs to start a thread for processing. If the connection does not do anything, it will cause unnecessary thread overhead.It is improved by the thread pool mechanism.The BIO method is suitable for the architecture with a relatively small number of connections and a fixed number of connections. This method has relatively high requirements on server-side resources, and concurrency is limited to applications. Before jdk1.4, it was the only io now, but the program is intuitive and easy to understand
Second, synchronous non-blocking I/O (NIO):
Synchronous non-blocking I/O, the server implementation mode is one request and one thread, that is, the connection request sent by the client will be registered on the multiplexer, and the multiplexer will poll only when there is an IO request connected to the connection.Start a thread for processing.The NIO method is suitable for architectures with a large number of connections and relatively short connections (light operation), such as chat servers, concurrency is limited to applications, and programming is more complicated, jdk1, 4 began to support
Third, asynchronous non-blocking I/O (AIO):
Asynchronous non-blocking I/O, the server implementation mode is one valid request for one thread, and the client's IO request is completed by the operating system first and then notifies the server to use its startup thread for processing.The AIO method is suitable for architectures with a large number of connections and a relatively long connection (heavy operation), such as an album server, which fully calls the OS to participate in concurrent operations, and the programming is more complicated, and jdk1.7 began to support it.
Fourth, the difference between IO and NIO:
IO is stream-oriented, NIO is buffer-oriented
IO's various streams are blocking, NIO is non-blocking mode
Java NIO's selection allows a single thread to monitor multiple input channels, multiple channels can be registered with a selector, and then a single thread is used to "select" channels: those channels already have inputs that can be processedOr select a channel that is ready to write.This selection mechanism makes it easy for a single thread to manage multiple channels
5. The difference between synchronous and asynchronous:
Synchronization: Send a request, wait for the return, and then send the next request, synchronization can avoid deadlocks and dirty reads
Asynchronous: Send a request without waiting for the return, you can send the next request at any time, which can improve efficiency and ensure concurrency
The focus of synchronous and asynchronous is on the message communication mechanism,
Blocking and non-blocking focus on the state of the program while waiting for the result of the call (message, return value):
A blocking call means that the current thread will be suspended before the call result returns.The calling thread does not return until it has the result.
A non-blocking call means that the call will not block the current thread until the result is not immediately available
What is the actual difference between AIO and NIO
Example explanation
Haidilao is delicious, but there are often queues.Let's take this example from life to explain.
- Customer A went to eat Haidilao and just sat and waited for an hour before eating hot pot.(BIO)
- Customer B went to eat Haidilao, he saw that he had to wait for a long time, so he went to the mall, and every time he went shopping for a while, he ran back to see if there was a line for him.So he ended up shopping and eating Haidilao.(NIO)
- Customer C went to eat Haidilao, because he is a senior member, so the store manager said, you can go to the mall to play casually, and I will call you immediately when there is a seat.So C customers don't have to sit and wait, and they don't have to run back every once in a while to see if they can wait, and finally eat Haidilao (AIO)
Which method is more efficient?Is it obvious at a glance?
边栏推荐
- MySQL的用户临时表与内部临时表
- 2022年固定资产管理系统的概况
- 故障分析 | Sql_slave_skip_counter 使用不规范对复制的影响
- [Metaverse Omi Says] See how UCOUCO integrates performance art into the Metaverse
- PTA 习题2.1 简单计算器
- 幂次方(暑假每日一题 20)
- J9 digital science: Web 3.0 is about data ownership or decentralized?
- Spotify expresses its architectural design using the C4 model
- DAY25:逻辑漏洞
- How to break the DeepFake face-changing scam?turn him over
猜你喜欢
shell------ commonly used gadgets, sort, uniq, tr, cut
多线程知识点总结之温故而知新
Nvidia's gaming graphics card revenue plummets / Google data center explosion injures 3 people / iPhone battery percentage returns... More news today is here...
FPGA的虚拟时钟如何使用?
IDEA中xml文件头报错:URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs)
How to break the DeepFake face-changing scam?turn him over
多线程浅谈
ARM体系结构2:处理器内核和汇编指令集
郭晶晶家的象棋私教,好家伙是个机器人
shell之函数和数组
随机推荐
打工人的第27天-平凡但不平淡的日子
It is obvious that a unique index is added, why does it still generate duplicate data?
keepalived:主备配置
[OAuth2] Nineteen, OpenID Connect dynamic client registration
DAY25:逻辑漏洞复现
Defending risks with technology and escorting cloud native | Tongchuang Yongyi X Boyun held a joint product launch conference
Controller层代码这么写,简洁又优雅!
JWT:拥有我,即拥有权力
《广州市公路工程安全生产监督管理办法》印发,从六大方面进行修订
MUDA:对齐特定域的分布和分类器以实现来自多源域的跨域分类
04 【计算属性 侦听器】
J9数字论:关于DAO 特点的宏观分析
关于判断单峰数组的几种方法
1499. 满足不等式的最大值 堆/双端队列
mySQL add, delete, modify and check advanced
PTA Exercise 2.1 Simple Calculator
How to use [jmeter regular expression extractor] to solve the problem of returning the value as a parameter
【业务架构】价值链分析:提高客户价值和盈利能力
【API Management】What is API Management and why is it important?
FPGA中BEL Site Tile FSR SLR分别指什么?