The basic concepts of netty-blocking and non-blocking, synchronous and asynchronous

Blocking (Block) and non-blocking (Non-Block)

Blocking and non-blocking is a way of processing whether the data is ready when the process is accessing the data, when the data is not ready.

Blocking: It is often necessary to wait for the data in the buffer to be ready before processing other things, otherwise it has been waiting there.

Non-blocking: When our process accesses our data buffer, if the data is not ready, it will return directly without waiting. If the data is ready, return directly.

Synchronization and Asynchronous

Synchronous and asynchronous are based on the way applications and operating systems handle IO events. For example, synchronization: the application directly participates in IO read and write operations. Asynchronous: All IO reads and writes are handled by the operating system, and the application only needs to wait for notification.

When processing IO events in a synchronous manner, we must block on a method to wait for our IO events to complete (blocking IO events or by polling IO events). For asynchronous, all IO reads and writes are handed over operating system. At this time, we can do other things and do not need to complete the real IO operation. When the operation completes the IO, a notification will be given to our application.

Synchronous: Block to IO events, block to read or write. At this time we can't do our own thing at all. Let the read and write methods be added to the thread, and then block the thread to achieve, the performance overhead of the thread is relatively large.

Guess you like

Origin blog.csdn.net/madongyu1259892936/article/details/109669076