Regarding the JAVA network, there is a metaphorical summary before, to share with you:

Example: There is a chicken farm with chickens (Socket) from various farmers (Thread), and each farmer has established his own hen house (SocketChannel) in the farm.
1. BIO: Block IO, each farmer Staring at your chicken coop, once there are chickens laying eggs, go to pick up eggs;
2, NIO: No-Block IO-single Selector, farmers spend money to hire a breeder (Selector), and tell the breeder (register ) If any chickens have any situation (lay eggs), they must report to this farmer (select keys);
3. NIO: No-Block IO-Multi Selector, when the chicken house on the farm gradually increases, a breeder patrols (Polling) The time required for one time will continue to increase, so that farmers will know that their chickens lay eggs and there will be a large delay. How to solve it? That's right, please ask more breeders (multiple Selectors), and each breeder allocates and manages the chicken coop, so that the workload of one breeder can be reduced, and farmers can know more quickly whether their chickens lay eggs;
4. Epoll mode: If the Epoll method is adopted, how should the farm problem be improved? In fact, the breeder does not need to patrol the chicken coop anymore, but knows which chicken coop has croaked (active connection), and knows which farmer's chicken has laid eggs;
5. AIO: Asynchronous I / O, after the chicken has laid eggs The previous NIO method required the breeder to notify the farmer to pick the eggs. After the AIO model appeared, things became simpler. The breeder was responsible for the egg picking, and after the picking, the farmer was directly notified to pick it up. Farmers need to go to the chicken coop to collect eggs.

78 original articles published · 32 praised · 120,000 views

Guess you like

Origin blog.csdn.net/caofengtao1314/article/details/105117367