Java IO/NIO

#关于 JAVA 中 IO 的选择

前几周好好的看了下后端服务器端的代码,IO 用的是 select 模型,不是传统的 Stream IO,但是至于这两者之间的选择问题,倒是没怎么弄明白,今天在看 Apache HttpCore 的文档时看到了他们对于这两者的看法:

Blocking (or classic) I/O in Java represents a highly efficient and convenient I/O model well suited for high performance applications where the number of concurrent connections is relatively moderate. Modern JVMs are capable of efficient context switching and the blocking I/O model should offer the best performance in terms of raw data throughput as long as the number of concurrent connections is below one thousand and connections are mostly busy transmitting data. However for applications where connections stay idle most of the time the overhead of context switching may become substantial and a non-blocking I/O model may present a better alternative.

具体见文档