Basic concept blocking and non-blocking
阻塞是进行读写时, 如果当时没有东西可读,或者暂时不可写, 程序就进入等待, 直到有东西可读或者可写为止
Synchronous and asynchronous
同步是指的是用户操作后等待或者轮询的去查看操作是否就绪 异步是指用户某动作操作后便开始做其他动作,而当这个动作操作完成的时候用户会得到这个动作完成的通知
IO model Synchronous blocking IO (JAVA BIO):
In this way, the user process must wait for the IO operation to complete after initiating an IO operation, and the user process will not run until the IO operation is actually completed. Java's traditional IO model belongs to this way!
Synchronous non-blocking IO (Java NIO)
The user process initiates an IO operation to return to doing something else, but the user process needs to ask the IO operation to be ready from time to time, which requires the user process to constantly ask questions, thus introducing unnecessary waste of CPU resources.
Asynchronous blocking IO (Java NIO):
In this way, after the application initiates an IO operation, does not wait for the kernel IO operation to complete, and so on after the kernel completes the IO operation notifies the application, this is actually the synchronization and the asynchronous most crucial difference, the synchronization must wait or the initiative to ask whether the IO completes, then why say is blocked? Because this is done by 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 at the same time (if viewed from the UNP (UNIX Net programing) perspective, Select belongs to the synchronization operation. Because the process also needs to read and write data after select, it can improve 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, after the actual completion of the IO operation, the application will get the IO operation to complete the notification, at this time the user process only need to process the data, do not need to do the actual IO read and write operations, Because the actual IO read or write operation has been completed by the kernel
BIO, NIO, AIO application Scenario analysis:
The bio method is suitable for a small and fixed number of connections, which requires a high level of server resources, and is limited to applications, JDK1.4 the only choice before, but the program is intuitive and easy to understand.
The NIO approach is suitable for architectures with a large number of connections and short (light-operated) connections, such as chat servers, which are limited to applications, and are more complex to program, and JDK1.4 begin to support.
AIO mode allows for a number of connections and long-connected (re-operation) of the architecture, such as the album server, full call to the OS to participate in concurrent operations, programming more complex, JDK7 began to support.
Turn from: 65934828
Java-io Model (Bio,nio,aio)