1.io is stream-oriented, that is, when reading data, it is read from the stream one by one, so the data cannot be viewed as a whole and there is no buffer; nio is buffer-oriented, and the data is stored in the buffer. Reading data is performed in the buffer, so it is more convenient to perform data offset operations 2. io is blocked. When a thread operates io, if there is currently no data to read, the thread is blocked, and nio is a channel operation. io, so it is non-blocking. When a channel has no data to read, the channel can be switched to process other io 3. Nio has a selector, which means that threads can select multiple channels through the selector, while io can only process one
Assume the following scenario: on a 4-core machine, receive network requests, process business logic, and return the processing results to the client. The network requests are 10,000/s. During business logic processing, there are The operation of importing files requires blocking for 5 seconds of processing time, assuming that the transfer does not take time.
1. Use BIO processing:
Due to the long IO time in business logic processing, the processing thread will be blocked. In the case of multiple requests, one request will generate a thread to process the business, so within 5 seconds, 50,000 threads need to exist in the system. Used to handle business logic. The CPU will use most of its resources to handle thread scheduling.
2. Use NIO processing: The IO operations in NIO are asynchronous and will not block the business logic thread. In the case of multiple requests, 4 business threads are opened, one thread occupies one CPU core, and the business thread can be processed at full speed. business logic. For IO operations in the business, they can be processed asynchronously in the hardware, and messages are sent to the CPU for subsequent business processing when the data is ready. At this time, only four threads are needed to process the business efficiently, and the CPU is almost not idle. There is no need to consume resources in thread scheduling.
1.nio does memory mapping, eliminating one copy between user space and system space 2.nio is asynchronous, triggered response, non-blocking response, making full use of system resources, mainly CPU

0zhangzhun132·Just
1.io is stream-oriented, that is, when reading data, it is read from the stream one by one, so the data cannot be viewed as a whole and there is no buffer; nio is buffer-oriented, and the data is stored in the buffer. Reading data is performed in the buffer, so it is more convenient to perform data offset operations
2. io is blocked. When a thread operates io, if there is currently no data to read, the thread is blocked, and nio is a channel operation. io, so it is non-blocking. When a channel has no data to read, the channel can be switched to process other io
3. Nio has a selector, which means that threads can select multiple channels through the selector, while io can only process one
Purely done by hand, I hope it helps you
EOF
Assume the following scenario: on a 4-core machine, receive network requests, process business logic, and return the processing results to the client. The network requests are 10,000/s. During business logic processing, there are The operation of importing files requires blocking for 5 seconds of processing time, assuming that the transfer does not take time.
1. Use BIO processing:
Due to the long IO time in business logic processing, the processing thread will be blocked. In the case of multiple requests, one request will generate a thread to process the business, so within 5 seconds, 50,000 threads need to exist in the system. Used to handle business logic. The CPU will use most of its resources to handle thread scheduling.
2. Use NIO processing:
The IO operations in NIO are asynchronous and will not block the business logic thread. In the case of multiple requests, 4 business threads are opened, one thread occupies one CPU core, and the business thread can be processed at full speed. business logic. For IO operations in the business, they can be processed asynchronously in the hardware, and messages are sent to the CPU for subsequent business processing when the data is ready. At this time, only four threads are needed to process the business efficiently, and the CPU is almost not idle. There is no need to consume resources in thread scheduling.
Whether it is IO or NIO, it is a manifestation of the Linux network I/O model. It is recommended to learn the Linux network model.
1.nio does memory mapping, eliminating one copy between user space and system space
2.nio is asynchronous, triggered response, non-blocking response, making full use of system resources, mainly CPU
<h1>Hey hey</h1>