分工细化一
服务端可以定义两个EventLoopGroup 第一个是boss,第二个是worker的。将accept事件和read,write事件分开处理。
package com.xkj.learn;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import java.nio.charset.Charset;
@Slf4j
public class EventLoopServer {
public static void main(String[] args) {
new ServerBootstrap()
//第一个EventLoopGroup就是boss,负责处理ServerSocketChannel的accept事件
//第二个EventLoopGroup就是worker,负责处理SocketChannel的read,write事件
.group(new NioEventLoopGroup(), new NioEventLoopGroup(2))
.channel(NioServerSocketChannel.class) /
标签:netty,nio,细化,18,io,import,EventLoopGroup,channel
From: https://blog.csdn.net/qq_36352889/article/details/139708895