ServerBootstrap的init()方法中,有这样一段逻辑:if (handler != null) { pipeline.addLast(handler);}ch.eventLoop().execute(new Runnable() { @Override public void run() { pipeline.addLast(new ServerBootstrapAcceptor( ch, currentChildGroup, currentChildHandler, currentChildOptions, currentChildAttrs)); }});为什么对ServerBootstrapAcceptor的添加,要放到线程中执行,而不是直接同步添加?
5 回答

慕移动9481536
TA贡献1条经验 获得超0个赞
因为还没有将 Channel 注册到 Selector 对象上,所以还无法注册 Accept 事件到 Selector 上,所以事先添加了 ChannelInitializer 处理器,等待 Channel 注册完成后,再向 Pipeline 中添加 ServerBootstrapAcceptor 处理器。
添加回答
举报
0/150
提交
取消