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

View File

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