java foundation: BIO, NIO, AIO What is the difference?

simple

  • BIO: Block IO synchronous blocking IO, is what we usually use the traditional IO, which is characterized by simple and easy to use mode, low concurrent processing capability.
  • NIO: Non IO synchronous non-blocking IO, IO is the traditional upgrade, the client and the server through Channel (channel) communication, to achieve multiplexing.
  • AIO: Asynchronous IO is upgraded NIO, also known as NIO2, implements asynchronous non-blocking IO, event-based asynchronous IO operation and callback mechanism.

detailed

  • BIO (Blocking I / O): synchronous blocking I / O mode, the read data is written to be blocked waiting for its completion within a thread. In the case of active connections is not particularly high (less than stand-alone 1000), and this model is quite good, allowing each to focus on their connected I / O and simple programming model, it does not give much thought to overload the system, issues such as limiting. Thread pool itself is a natural funnel, some systems can not deal with a buffer or a connection request. However, when connected to the face of thousands or even one million, BIO traditional model is powerless. Therefore, we need a more efficient I / O processing model to cope with higher concurrency.
  • NIO (New I / O): NIO is a synchronous non-blocking I / O model, incorporated in the Java 1.4 NIO frame corresponding java.nio package, provided Channel, Selector, Buffer other abstract. NIO N can be understood as the Non-blocking, not simply New. It supports buffer-oriented, channel-based I / O operation method. NIO provides traditional BIO model Socket and ServerSocket corresponding SocketChannel and ServerSocketChannel two different socket channel to achieve both channel supports blocking and non-blocking modes. Blocking mode using just tradition, like support, is relatively simple, but the performance and reliability is not good; just the opposite non-blocking mode. For low load, low concurrent applications, can use synchronous blocking I / O rate and to enhance the development of better maintenance; high load, high concurrency (network) applications, use of non-blocking mode to develop NIO
  • AIO (Asynchronous I / O): AIO i.e. NIO 2. Introduced an improved version of NIO 2 NIO in Java 7, it is asynchronous non-blocking IO model. Asynchronous IO is based on the event and the callback mechanism to achieve, that is, after the application of the operation will be returned directly, will not plug in there, when background processing is complete, the operating system will notify the appropriate thread for subsequent operations. AIO is an acronym for asynchronous IO, although the NIO in network operation, provides non-blocking method, but IO NIO or synchronous behavior. For the NIO, the thread when our business is ready IO operations to be notified, and then they were operated by the IO thread itself, IO operation itself is synchronized. Access to relevant information online, I found that for the present application AIO is not very extensive, but also try to use the AIO had before Netty, but gave up.
Published 438 original articles · won praise 2 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_37769323/article/details/104603456