Advanced Java (10) - Network Programming

BIO, NIO, AIO
difference between the concepts above NIO vs IO (NIO will block execution to the background thread)

  • IO stream oriented, NIO oriented buffer
    • Java IO stream means for each read from the stream one or more bytes, until all bytes are read, they are not cached anywhere;
    • NIO is able to move forward and backward in the data stream, because the buffer for
  • IO flow is blocked, NIO flow is not blocked
    • Various Java IO streams are blocked. This means that when a thread calls read () or write (), the thread is blocked until there is some data to be read, or the data is completely written. The thread in the meantime can not do it again any thing
    • Java NIO non-blocking mode, the thread sends a request to read data from a channel, but it can only get the data currently available, if there is no data currently available, it will not get anything. NIO allows you to use only one (or several) single-threaded manage multiple channels (network connection or file), but at the cost of parsing the data may be more complicated than reading data from a blocking stream. 
    • Non-blocking write is true. A thread requests to write some data to a channel, but do not need to wait for it to be completely written, this thread can do something else at the same time.
  • Selector
    • Java NIO selector allows a single thread to monitor multiple input channels, you can register multiple channels using a selector, and then use a separate thread to "select" Channel: The channel already has an input that can be processed, or select the channel is ready to be written. This selection mechanism, such that a single thread is easy to manage a plurality of channels. 
      Reference: https://blog.csdn.net/evan_man/article/details/50910542

NIO communication framework Mina, Netty, Grizzly
https://blog.csdn.net/wang_snake/article/details/79249972

BIO, NIO, AIO Ku别
https://blog.csdn.net/guanghuichenshao/article/details/79375967

Network programming
https://h2pl.github.io/categories/ backend / Java network programming with NIO / page / 2 /

Guess you like

Origin blog.51cto.com/4397014/2436900