Is it useful to distribute incoming connections between n threads, each with its own independent NIO Selector , where n is, say, the number of cores on the server? Suppose I am writing a server that should handle several client connections. I could be something like:
selector.select(); Iterator<SelectionKey> i = selector.selectedKeys().iterator(); while (i.hasNext()) { SelectionKey key = i.next(); i.remove(); if (!key.isValid()) continue; if (key.isAcceptable()) {
Do you guys think that makes sense? I mean, n threads, each with a different selector? Or should I just stick to one selector thread that processes OP_READ for all connections? Or maybe something else?
java multithreading selector nio
Eduardo bezerra
source share