// 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;
...
}
// 选择器核心方法 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 删除。