BIO, NIO, AIO What is the difference?

  • BIO: Thread initiate IO requests, regardless of whether the kernel is ready IO operation, starting from the initiating request, the thread blocks until the operation is complete.
  • NIO: IO thread initiate a request to return immediately; after the kernel ready for IO operations, by calling the registered callback function to do IO operation notification thread, the thread began to block until the operation is complete.
  • AIO: IO thread initiate a request to return immediately; after memory ready for IO operations, IO operation to do, until the operation is completed or failed to complete registration by calling the callback function notifies the thread does IO operation or failure.

 

  • BIO is a connecting thread.
  • NIO is a request thread.
  • AIO is a valid request a thread.

 

  • BIO: synchronous and blocking, server model to achieve a connection to a thread that has a client connection request on the server side need to start a thread for processing, if the connection does not do anything to cause unnecessary overhead of thread, of course, can improved thread pooling mechanism.
  • NIO: synchronous non-blocking, the server requests a mode of realization of a thread, i.e. the connection request sent by the client are registered to the multiplexer, the multiplexer is connected to the polling I / O request when a start thread for processing.
  • AIO: non-blocking asynchronous server mode to achieve a valid request a thread, the client OS IO requests are made to complete the application and then notify the server to start a thread for processing.

 

Applicable scene analysis

  • The number of connected mode applies to relatively small BIO and fixed architecture, server resources in this way is relatively high, limited concurrent applications, the JDK1.4 previously only option, but the program intuitive and easy to understand.
  • NIO connection number suitable for multi-mode and connected to short (light operation) architecture, such as chat server, limited concurrent applications, more complex programming, starts the JDK1.4 support.
  • AIO way to use more than the number of connections and the connection is relatively long (heavy operation) architecture, such as the album server, call the OS to fully participate in concurrent operation, programming is more complex, JDK7 began to support.


Excerpt: https://blog.csdn.net/u013068377/article/details/70312551
incorporated by reference code: https://www.cnblogs.com/barrywxx/p/8430790.html


 


 

All resources resources are summarized in the public No.


 

 

Guess you like

Origin www.cnblogs.com/ConstXiong/p/11921576.html