首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >01-EventLoopGroup与EventLoop与选择器

01-EventLoopGroup与EventLoop与选择器

原创
作者头像
spbreak
发布2023-10-10 00:28:12
发布2023-10-10 00:28:12
16400
代码可运行
举报
文章被收录于专栏:nettynetty
运行总次数:0
代码可运行

EventLoopGroup与EventLoop与chooser

  • EventLoopGroup事件循环组的子集children[]成员为EventLoop事件循环
  • EventLoopGroup是EventLoop的一个管理容器
  • Chooser选择器用于从EventLoopGroup中选举出EventLoop, 以供外部使用
  • Chooser内部实现选举编历逻辑
事件循环组的选择器
事件循环组的选择器

github代码实现

代码语言:javascript
代码运行次数:0
运行
复制
// EventLoopGroup的属性有EventLoop集合与chooser选择器
public class NioEventLoopGroup implements EventExecutorGroup {
    private final EventExecutor[] children;

    private static final int DEFAULT_EVENT_LOOP_THREADS = 16;

    private final EventExecutorChooserFactory.EventExecutorChooser chooser;

    ...
}
代码语言:javascript
代码运行次数:0
运行
复制
// 选择器核心方法 executors[idx.getAndIncrement() & executors.length - 1];
private static final class PowerOfTwoEventExecutorChooser implements EventExecutorChooser {
    private final AtomicInteger idx = new AtomicInteger();
    private final EventExecutor[] executors;

    PowerOfTwoEventExecutorChooser(EventExecutor[] executors) {
        this.executors = executors;
    }

    @Override
    public EventExecutor next() {
        return executors[idx.getAndIncrement() & executors.length - 1];
    }
}

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • EventLoopGroup与EventLoop与chooser
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档