NIO learning (a): Basic Concepts

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/outsanding/article/details/102649662
background
  1. Java IO and NIO-related knowledge is the study of the relationship between kernel space and user space (application):

    Copied from kernel space to user space? Related to the zero-copy knowledge .

    Ready to wait for the user space kernel space data? Obstruction knowledge

    User space is not prepared to wait for kernel space data? Non-blocking knowledge

    User space to kernel space initiative to read the data? Synchronization knowledge

    Kernel space data ready callback to the user space? Asynchronous knowledge


basic concepts
  1. Blocking IO (BIO, Blocking Input Output) , JDK1.4 before .
    Definitions: A calls B, A has been waiting to return to B, and then doing nothing.

    Java IO specific process: application waits for kernel space data preparation, wait until the data is ready, what other things do not.

  2. Non-blocking (NIO, Non-Blocking Input Output ), JDK1.4 to of JDK1.6 .
    Definitions: A calls B, A B not wait to return and instead do other things.

    Java NIO specific process: the application is not ready to wait for kernel space data.

  3. Sync (synchronize)
    is defined broadly: A calls B, A waiting to return to B, and then doing nothing.

    The specific process: the user space to kernel space initiative to read data.

  4. Asynchronous (AIO, asynchronize Input Output), JDK1.7 and beyond .
    Defined broadly: A calls B, A B not wait to return and instead do other things.

    Java AIO specific process: kernel space data ready callback to the user space.

Java IO IO is blocked

Oriented flow programming, and this stream is either an input stream, either the output stream, only one of them, can not be both an input stream and output stream.

Java NIO non-blocking IO
  1. Three core components
    Selector
    Channel
    Buffer

  2. Oriented block (block) program or facing (buffer) buffer programming.

  3. Selector
    is a multiplexer selector select Channel (SelectableChannel) object . Multiple means to be registered simultaneously on multiple Channel Selector. Multiplexing means that the Selector is actually a single-threaded. Selector concept is the original source operating system has a blocking method called select, and now the operating system using epoll method, the idea came on the use of a name: selector. Then according to its characteristics, so defined as the multiplexer selector .

  4. Channel
    Channel can be understood as in java.io stream, so understanding there is no problem. Data is initially written by Channel Buffer in by Buffer to our program, not directly from our application to the Channel.

  5. Buffer

    Buffer itself is a piece of memory, the underlying implementation is actually an array, reading and writing are achieved by Buffer.
    Buffer itself can read and write, you can call the flip method: Buffer.flip () to re-position Buffer property of, limit assignment. Read and write during the time of conversion, be sure to call the show at the flip method.


summary
  1. From the bottom of the Java process IO operations to understand: blocking and non-blocking, synchronous and asynchronous concepts .
  2. Understand what Java IO and Java NIO defined Yes.
  3. Java IO bottom: blocking and non-blocking system study of the relationship between space and the external input and output; and synchronous and asynchronous study is the relationship between system and user space.

Guess you like

Origin blog.csdn.net/outsanding/article/details/102649662