Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
关于IO多路复用为什么搭配非阻塞IO? #482
关于IO多路复用为什么搭配非阻塞IO? #482
Comments
jinshuai86
commented
Dec 5, 2018
|
|
Java NIO 被称为非阻塞 IO,这是与传统的 BIO(阻塞 IO)相对的。BIO 执行 accept 等操作时会一直阻塞,而 NIO 不会阻塞。只要理解了 Reactor 模型就能理解这里的非阻塞意义。 上面的 select 文档提到的非阻塞用途和这里的不太一样。 |
|
这里的非阻塞特性允许一个线程处理多个 Channel,而传统的 BIO 一个线程只能处理一个 Channel。
你理解感觉不对,这里的非阻塞描述的是第一个阶段,而 select 文档那里写的非阻塞描述的是第二个阶段。 |
|
谢谢大佬,之前理解的IO复用第一阶段(调用select()直到有可用socket)一直会阻塞当前线程,然后在第二阶段(copy data from kernel to user)如果socket设置了非阻塞,在内核没有数据时(就像select手册里说的由于检验错误丢弃了已经准备好的数据)进行I/O operation 不会阻塞当前线程。我理解应该有问题,我再去查查资料 |
|
@jinshuai86 IO 多路复用在第一阶段既可以说成是阻塞,也可以说成是非阻塞,就看从哪方面去考虑。 |
|
هل تدعم العربية |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
