update netty优化业务线程池

This commit is contained in:
Lemon
2025-07-22 17:23:02 +08:00
parent 56fe5c1f71
commit eabac85e4e
2 changed files with 7 additions and 4 deletions

View File

@@ -16,6 +16,9 @@ import java.util.concurrent.TimeUnit;
@Component @Component
public class NettyServerChannelInitializer extends ChannelInitializer<SocketChannel> { public class NettyServerChannelInitializer extends ChannelInitializer<SocketChannel> {
@Resource
private NettyServerHandler nettyServerHandler;
// 引入业务线程池 // 引入业务线程池
final EventExecutorGroup businessGroup = new DefaultEventExecutorGroup(16); final EventExecutorGroup businessGroup = new DefaultEventExecutorGroup(16);
@@ -31,7 +34,7 @@ public class NettyServerChannelInitializer extends ChannelInitializer<SocketChan
// 读超时时间设置为30s0表示不监控 // 读超时时间设置为30s0表示不监控
pipeline.addLast(new IdleStateHandler(30, 0, 0, TimeUnit.SECONDS)); pipeline.addLast(new IdleStateHandler(30, 0, 0, TimeUnit.SECONDS));
// pipeline.addLast("handler", nettyServerHandler); // pipeline.addLast("handler", nettyServerHandler);
pipeline.addLast(businessGroup, new NettyServerHandler()); // 消息先进入业务线程池 pipeline.addLast(businessGroup, nettyServerHandler); // 消息先进入业务线程池
pipeline.addLast(new EchoServerHandler()); pipeline.addLast(new EchoServerHandler());
} }

View File

@@ -34,8 +34,8 @@ import java.util.concurrent.ConcurrentHashMap;
@Component @Component
public class NettyServerHandler extends ChannelInboundHandlerAdapter { public class NettyServerHandler extends ChannelInboundHandlerAdapter {
// @Resource @Resource
// private YKCBusinessService ykcService; private YKCBusinessService ykcService;
/** /**
* 管理一个全局map保存连接进服务端的通道数量 * 管理一个全局map保存连接进服务端的通道数量
@@ -44,7 +44,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
protected static final List<String> notPrintFrameTypeList = Lists.newArrayList(); // "0x03" protected static final List<String> notPrintFrameTypeList = Lists.newArrayList(); // "0x03"
private final YKCBusinessService ykcService = new YKCBusinessServiceImpl(); // private final YKCBusinessService ykcService = new YKCBusinessServiceImpl();
/** /**
* 有客户端连接服务器会触发此函数 * 有客户端连接服务器会触发此函数