Basic Concepts
blocking and non-blocking
Blocking is when reading and writing, if nothing is readable at the time, or is temporarily not writable, the program goes into waiting until something is readable or writable, and
if nothing is readable or writable, the read-write function returns immediately without waiting.
Synchronous and asynchronous
Synchronization refers to the user after the operation of the waiting or polling to see whether the operation is ready
asynchronous refers to the user after an action to start doing other actions, and when the action is completed when the user will get the action completed notice
IO Model
Synchronous blocking IO (JAVA BIO):
In this way, the user process must wait for the IO operation to complete after an IO operation is initiated, and the user process will not run until the IO operation is actually completed. The Java traditional IO model belongs in this way. synchronous non-blocking io (Java NIO)
The user process initiates an IO operation to return to doing other things, but the user process needs to ask the IO operation to be ready from time to time, which requires the user process to continually inquire, thereby introducing unnecessary waste of CPU resources. Asynchronous blocking Io (Java NIO):
This means that after the application initiates an IO operation, do not wait for kernel IO operations to complete, and so the kernel completes the IO operation will notify the application, this is actually synchronous and asynchronous the most critical difference, synchronization must wait or actively ask IO is completed, then why is it blocked? Because this is done through a select system call, and the Select function itself is implemented in a blocking way, the advantage of using the Select function is that it can listen to multiple file handles simultaneously (if viewed from the UNP (UNIX Net programing) perspective, The select belongs to a synchronization operation. Because the process also needs to read and write data after the Select, it increases the concurrency of the system. (Java AIO (nio.2)) asynchronous non-blocking IO:
In this mode, the user process only needs to initiate an IO operation and then return immediately, and when the IO operation is actually completed, the application will be notified of the IO operation, at which point the user process needs only to process the data, without the need for actual IO read and write operations, Because the real IO read or write operation has been completed by the kernel of BIO, NIO, AIO application scenario analysis:
The bio method is suitable for a small number of connections and a fixed architecture, this approach to the server resource requirements are relatively high, concurrent limited to applications, JDK1.4 before the only choice, but the program intuitive simple and easy to understand.
NiO method suitable for the number of connections and relatively short (light operation) of the architecture, such as chat server, concurrency limited to applications, programming is more complex, JDK1.4 began to support.
AIO mode for the number of connections and relatively long (heavy operation) of the architecture, such as photo albums Server, fully invoke the OS to participate in concurrent operations, programming more complex, JDK7 began to support.