Java's NIO is Synchronize non-blocking, but why is its core Selector.select () blocking?

Java"s NIO is Synchronize non-blocking, but why is its core Selector.select () blocking? Is it not contradictory?

Selector selector = Selector.open();
while (true) {
    int nReady = selector.select(); // 
    Set<SelectionKey> keys = selector.selectedKeys();
    Iterator<SelectionKey> it = keys.iterator();
    //...
}
Dec.16,2021

Don't confuse select with io itself. Select is a butler, and a select can check multiple io reads and writes at the same time, and each io is non-blocking.

in addition, don't forget that selectNow, even the butler, select, is non-blocking.


the phrase "NIO" is Synchronize non-blocking means that for an IO, it is Synchronize non-blocking, which means that the thread that owns the IO does not block, while in NIO, a thread has a lot of IO, and any IO has data, the selector is awakened, so you can think of it this way: in this thread, when IOA has no data waiting, IOB may be being processed. So the thread is not blocked by the IOA.
feels that you are too obsessed with blocking and non-blocking, so you don't have to worry so much about it.
and NIO. I think strictly speaking, it should be multiplexing, not Synchronize non-blocking

.
Menu