I. Basic Concepts
Synchronization: the caller will wait until the result goes down. I call a result and wait until the result is returned.
Asynchronous: you do not need to wait for the result after calling the interface. I will be notified of the result.
The difference between the two is whether or not to wait for the result. What will wait for the result is synchronization, and what will not wait for the result is asynchronous.
Blocking: The current thread is suspended while waiting for the returned result.
Non-blocking: I can do other things while waiting for the returned results.
Blocking and non-blocking focus on the status when the program is waiting for the call result (message, return value.
For example, I called the bookstore and asked my boss if he had the book "Distributed System.
The synchronization mechanism is: the boss will say, wait for me to check, the result may have been checked for five minutes, or for several days. After checking, let me know, I have been waiting for it.
The asynchronous mechanism is: the boss will say, wait for me to find it and give you a call. Notify me through callback.
The blocking mechanism is: when you wait for a response, you will suspend yourself until you get the result of this book.
The non-blocking mechanism is: no matter whether the boss tells you, you play first, but check whether the boss has answered you later.
Ii. Bio (Block Io blocking Io): the server will open a dedicated thread for each client link, that is, the relationship between 1vs1. The number of threads that a server can start is fixed, if a bunch of requests come in, the server will definitely be suspended. This solution is not good.
Iii. NiO (non-block Io synchronous non-blocking Io ):
Bio, NiO, Aio