当前位置:网站首页>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?
边栏推荐
猜你喜欢

【OAuth2】二十、OAuth2扩展协议 PKCE

CAD转WPF: 关于CAD图纸文件转换为WPF矢量代码文件(xaml文件)的技巧

【元宇宙欧米说】听兔迷兔如何从虚拟到现实创造潮玩新时代
![[OAuth2] 20. OAuth2 Extended Protocol PKCE](/img/ff/37f3be22bf209222cadaf5d11f951a.png)
[OAuth2] 20. OAuth2 Extended Protocol PKCE

多线程浅谈

07 【动态组件 组件注册】

FPGA时钟篇(二) 7系列clock region详解

【Enterprise Architecture】Agile and Enterprise Architecture: Strategic Alliance

I don't want to do accounting anymore, Die changed to a new one, moved forward bravely, and finally successfully passed the career change test to double his monthly salary~

The first offline workshop in 2022!Data application experience day for application developers is coming | TiDB Workshop Day
随机推荐
FPGA时钟篇(一) 7系列的时钟结构
1-31部 1-31套 和硬件工程师90天学习资料及笔记汇总
ARM体系结构2:处理器内核和汇编指令集
人
并发的基本概念,操作,容器
J9 digital science: Web 3.0 is about data ownership or decentralized?
原型和原型链
【API架构】使用 JSON API 的好处
CTFSHOW七夕杯web
Linux下载安装MySql
1499. 满足不等式的最大值 堆/双端队列
刷题工具h
go web之cookie
Controller层代码这么写,简洁又优雅!
【企业架构】敏捷与企业架构:战略联盟
Basic concepts, structures, and classes of thread pools
高等数学(第七版)同济大学 习题4-3 个人解答
JWT:拥有我,即拥有权力
shell------常用小工具,sort,uniq,tr,cut
故障分析 | Sql_slave_skip_counter 使用不规范对复制的影响