Java in 2011: threaded sockets VS NIO: what to choose on 64bit OS and latest Java version?

前端 未结 5 1249
囚心锁ツ
囚心锁ツ 2020-12-23 18:46

I\'ve read several posts about java.net vs java.nio here on StackOverflow and on some blogs. But I still cannot catch an idea of when should one prefer NIO over threaded soc

5条回答
  •  一个人的身影
    2020-12-23 18:54

    What most often is overlooked is that NIO allows zero copy handling. E.g. if you listen to the same multicast traffic from within multiple processes using old school sockets on one single server, any multicast packet is copied from the network/kernel buffer to each listening application. So if you build a GRID of e.g. 20 processes, you get memory bandwidth issues. With nio you can examine the incoming buffer without having to copy it to application space. The process then copies only parts of the incoming traffic it is interested in.

    another application example: see http://www.ibm.com/developerworks/java/library/j-zerocopy/ for an example.

提交回复
热议问题