当前位置:网站首页>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增删改查进阶
【元宇宙欧米说】看UCOUCO如何将行为艺术融入元宇宙
1 活动时间与安排
shell iterates over folders and outputs
《广州市公路工程安全生产监督管理办法》印发,从六大方面进行修订
js读取excel时间格式转换
幂次方(暑假每日一题 20)
MUDA:对齐特定域的分布和分类器以实现来自多源域的跨域分类
shell------ commonly used gadgets, sort, uniq, tr, cut
【分布式】资源与事务:可观测性的基本二重性
打工人的第27天-平凡但不平淡的日子
多线程浅谈
DAY25: Logic vulnerability recurrence
不想再干会计了,蝶变向新,勇往直前,最后成功通过转行测试实现月薪翻倍~
shell之函数和数组
Flink快速上手 完整使用 (第二章)
The first offline workshop in 2022!Data application experience day for application developers is coming | TiDB Workshop Day
CTFSHOW七夕杯web
刷题工具h
硬件工程师90天学习资料及笔记汇总20220730







![[OAuth2] Nineteen, OpenID Connect dynamic client registration](/img/01/2f318a06e130cc222aa1736abbd152.png)

