[英]Why Netty uses reference counting instead of just one ByteBuffer per connection when NIO is single-threaded?
I am confused why Netty 5.0 makes you use reference counting for ByteBuffers. 我很困惑为什么Netty 5.0会让你使用ByteBuffers的引用计数。 Isn't Java NIO supposed to be single-threaded, in other words, one selector thread for many connections?
是不是Java NIO应该是单线程的,换句话说,一个选择器线程用于许多连接? Each client needs its own
ByteBuffer
and that's it, no pooling should be needed unless I am missing something. 每个客户端都需要自己的
ByteBuffer
,就是这样,除非我遗漏了什么,否则不需要池化。
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
ByteBuf m = (ByteBuf) msg; // (1)
try {
long currentTimeMillis = (m.readUnsignedInt() - 2208988800L) * 1000L;
System.out.println(new Date(currentTimeMillis));
ctx.close();
} finally {
m.release();
}
}
Source: http://netty.io/wiki/user-guide-for-5.x.html 资料来源: http : //netty.io/wiki/user-guide-for-5.x.html
It's because we don't know exactly what people will do with the ByteBuf. 这是因为我们不知道人们将如何处理ByteBuf。 Also we support writing from different threads etc.
我们也支持从不同的线程等写作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.