首页  

ServerBootstrap handler()和childHandler()的区别     所属分类 netty 浏览量 1151
int bossThreads = 2;
int workerThreads = 16;

EventLoopGroup bossGroup = new NioEventLoopGroup(bossThreads);
EventLoopGroup workerGroup = new NioEventLoopGroup(workerThreads);
        
        
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
// 去掉这个 启动时不会打印日志
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new EchoServerInit());
Channel ch = b.bind(port).sync().channel();
            
handler      在初始化时就会执行
childHandler 在客户端成功连接后才执行

option和childOption 类似

上一篇     下一篇
netty运行原理

netty4日志

UnsupportedClassVersionError处理

性能及问题排查合集

grafana使用技巧

监控系统安装配置及使用