
这个是源码中默认的线程数。

因为自己的cpu是8核心的,所以是cpu数量的2倍,这个是默认值
EventLoopGroup bossGroup = new NioEventLoopGroup(2);
EventLoopGroup workGroup = new NioEventLoopGroup(2);
如果我们这样设置
客户端有4个请求连接会是什么样
nioEventLoopGroup-3-1
ctx = ChannelHandlerContext(Nhandler#0, [id: 0xaee4fec7, L:/127.0.0.1:12312 - R:/127.0.0.1:55988])
client:大哥,大哥,大哥
address:/127.0.0.1:55988
nioEventLoopGroup-3-2
ctx = ChannelHandlerContext(Nhandler#0, [id: 0x231c2480, L:/127.0.0.1:12312 - R:/127.0.0.1:56039])
client:大哥,大哥,大哥
address:/127.0.0.1:56039
nioEventLoopGroup-3-1
ctx = ChannelHandlerContext(Nhandler#0, [id: 0xdc20672e, L:/127.0.0.1:12312 - R:/127.0.0.1:56078])
client:大哥,大哥,大哥
address:/127.0.0.1:56078
nioEventLoopGroup-3-2
ctx = ChannelHandlerContext(Nhandler#0, [id: 0x4e6be1b1, L:/127.0.0.1:12312 - R:/127.0.0.1:56116])
client:大哥,大哥,大哥
address:/127.0.0.1:56116
其实就是轮询。
System.out.println("ctx = " + ctx);
System.out.println("ctx.channel() = " + ctx.channel());
System.out.println("ctx.pipeline() = " + ctx.pipeline());
ctx就是有web的
本文深入探讨了Netty框架中的线程模型,特别是在8核CPU环境下,如何通过配置NioEventLoopGroup来实现高效的并发处理。通过实例分析,解释了当客户端发起多个请求时,线程是如何进行轮询分配的。
353

被折叠的 条评论
为什么被折叠?



