In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "what are BIO,NIO and AIO in the Java IO model". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are BIO,NIO and AIO in the Java IO model?"
I. Ipicuro model 1.1 basic explanation of Icancano model
A simple understanding of the Icano model: what kind of channel is used to send and receive data, which largely determines the performance of program communication.
1.2Three network programming modes supported by Java
Java supports three network programming models: BIO, NIO, and AIO.
1.3 JavaBIO (synchronous blocking)
JavaBIO: traditional blocking mode
Synchronous and blocking (traditional blocking), the server implementation mode is to connect to a server, that is, when the client has a connection request, the server needs to start a thread to process it. If the connection does nothing, it will cause unnecessary thread overhead.
The following figure shows the simple execution process of BIO
Traditional blocking type
The disadvantage of BIO is that the client is always connecting to the server, and the server will set up a thread for each client to process the client, but sometimes the client does not always IO the server, so this will cause the server to block, resulting in a lot of unnecessary thread overhead and waste of resources to the server.
1.4 JavaNIO (synchronous non-blocking)
JavaNIO: synchronous non-blocking
Synchronous non-blocking, server implementation mode for a thread to handle multiple requests (connections), that is, connection requests sent by the client will be registered with the multiplexer (Selector), and multiplexed polling will be processed when the connection has an Imodo request.
The following figure shows the simple execution process of NIO
Advantages of NIO
Because the client does not IO the server all the time, it is polled through the Selector selector and evenly distributed to the clients that need to IO the server, thus taking advantage of the idle time of the client to save the server memory consumption.
Of course, if the number of clients increases, the server will open another Thread connection Selector for polling allocation, and so on, so as to fully reduce memory consumption
1.5 JavaAIO (Asynchronous non-blocking)
JavaAIO: asynchronous non-blocking
Asynchronous non-blocking, AIO introduces the concept of asynchronous channel and adopts Proactor mode, which simplifies programming and starts threads with valid requests. Its characteristic is that the server program is notified to start threads to process after the completion of the operating system. It is generally suitable for applications with a large number of connections and a long connection time.
AIO has not been widely used at present.
AIO has a very close relationship with the operating system.
We will no longer draw pictures and explain them. AIO can understand it.
II. Analysis of applicable scenarios for BIO, NIO and AIO 2.1 BIO application scenarios
The BIO method is suitable for the architecture with a small number of connections and a fixed number of connections. This method requires high server resources, and concurrency is limited to the application. JDK1.4 was the only choice before, but the program is simple and easy to understand.
2.2 NIO application scenario
NIO mode is suitable for architectures with a large number of connections and short connections (light operation), such as chat server, on-screen comment system, server-to-server communication, etc., because programming is complicated, JDK1.4 starts to support it.
2.3 AIO application scenario
AIO method is used in architectures with a large number of connections and long connection time (heavy operation), such as photo album server, fully calling the OS operating system to participate in concurrent operations, programming is more complex, JDK1.7 begins to support
At this point, I believe you have a deeper understanding of "what are BIO,NIO and AIO in the Java IO model". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.