when implementing a messaging server with java, should we select Java bio or Java nio? what factors need to be considered?
-
possible duplicate of [What is the difference between Tomcat's BIO Connector and NIO Connector?](http://stackoverflow.com/questions/11032739/what-is-the-difference-between-tomcats-bio-connector-and-nio-connector) – Guy Schalnat Jul 12 '15 at 02:52
1 Answers
NIO
allows you to manage multiple channels (network connections or files) using only a single (or few) threads, but the cost is that parsing the data might be somewhat more complicated than when reading data from a blocking stream.
If you need to manage thousands of open connections simultanously, which each only send a little data, for instance a messaging server, implementing the server in NIO
is an advantage. Similarly, if you need to keep a lot of open connections to other computers, e.g. in a P2P network, using a single thread to manage all of your outbound connections might be an advantage (BIO
)
If you have fewer connections with very high bandwidth, sending a lot of data at a time, standard BIO
server implementation should be your choice.
Read this tutorial for more details

- 3,527
- 2
- 19
- 37