为了账号安全,请及时绑定邮箱和手机立即绑定

为什么Netty服务端启动时ServerBootstrapAcceptor的添加要放到线程中?

为什么Netty服务端启动时ServerBootstrapAcceptor的添加要放到线程中?

binarylife 2019-09-24 23:07:47
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 处理器。

查看完整回答
反对 回复 2021-01-16
  • 5 回答
  • 0 关注
  • 1288 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信