refactor: replace NioEventLoopGroup with MultiThreadIoEventLoopGroup to utilize NioIoHandler factory in UDP and TCP Netty servers

This commit is contained in:
Vickey
2026-02-11 11:58:48 +08:00
parent 0adff1532b
commit 01078a784d
2 changed files with 6 additions and 12 deletions
@@ -18,11 +18,8 @@
package io.github.pnoker.driver.service.netty.tcp;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.*;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.bytes.ByteArrayEncoder;
@@ -64,7 +61,7 @@ public class NettyTcpServer {
*/
@SneakyThrows
public void start(int port) {
EventLoopGroup group = new NioEventLoopGroup();
EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
try {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(group)
@@ -18,11 +18,8 @@
package io.github.pnoker.driver.service.netty.udp;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.*;
import io.netty.channel.nio.NioIoHandler;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.handler.timeout.WriteTimeoutHandler;
import lombok.SneakyThrows;
@@ -51,7 +48,7 @@ public class NettyUdpServer {
*/
@SneakyThrows
public void start(int port) {
EventLoopGroup group = new NioEventLoopGroup();
EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
try {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group)