NOTE
3.1 Comparison of the Three I/O Models
Relationship between Java I/O and system calls, BIO/NIO/AIO classification, comparison, and references.
This is a historical learning note and may contain outdated or incomplete understanding.
1. Relationship Between Java I/O and System Calls

1.1. I/O Types of System Calls
2. Java I/O Classification
2.1. BIO
Synchronous blocking I/O: a connection to a thread.
On the server side, multiple threads are needed to process multiple client connections and read/write requests. Generally, ServerSocket uses one thread (accepting new connections), and each client Socket uses one thread (read or write).
It belongs to synchronous blocking in the I/O model.

2.2. NIO
Synchronous non-blocking I/O: a request a thread.
On the server side, one thread can process multiple client connections and read/write requests. Generally, a Selector monitors client connections (accepting new connections). Each incoming connection creates a Channel. The Selector polls these Channels, and when an event occurs it is handed to the application for processing (read or write).
It belongs to I/O multiplexing in the I/O model and is implemented using epoll on Linux.

2.3. AIO
Asynchronous non-blocking I/O: a valid request a thread.
On the server side, one thread can process multiple client connections and read/write requests. Compared with NIO, I do not need to poll synchronously. The work is handed to the operating system asynchronously, and I am notified through a callback when processing is complete.
This is an interface standard. An operating system may implement it or may not. Linux does not implement it.
It belongs to asynchronous I/O in the I/O model. It uses epoll on Linux and IOCP on Windows.

3. I/O Comparison
3.1. NIO vs. BIO
| BIO | NIO | |
|---|---|---|
| Stream-oriented | Buffer-oriented | |
| Blocking | Non-blocking (can handle other things) | |
| None | Selector (one thread can serve multiple Channels) |
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub