简体   繁体   中英

java NIO read/write independently

While Selector.select() waits in blocking mode for either of read/write ops, is it possible to push a write message to a client? How to move the Selector from blocking mode to write mode? The trigger could be a background thread placing data which needs to be written to a given channel.

Does Selector retain state of all the connections once they are accepted? Is it possible to have one thread solely for reading and other for writing?

While Selector.select() waits in blocking mode for either of read/write ops, is it possible to push a write message to a client?

Yes, just call write() .

How to move the Selector from blocking mode to write mode?

There is no such thing as write mode of a Selector.

Does Selector retain state of all the connections once they are accepted?

I don't know what this means, but you seem have a complete misunderstanding of how a Selector works.

Is it possible to have one thread solely for reading and other for writing?

Certainly, but in that case there is no point in using a Seector at all. You would be better off using Sockets and streams.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM