我们知道Netty可以这样创建boss、work的EventLoopGroup,如果nThreads有多个呢,如何处理分配accept的呢?
EventLoopGroup bossGroup = new NioEventLoopGroup(1); EventLoopGroup workerGroup = new NioEventLoopGroup();
借用下参考资料的图片:
private final class PowerOfTwoEventExecutorChooser implements EventExecutorChooser { @Override public EventExecutor next() { return children[childIndex.getAndIncrement() & children.length - 1]; } } private final class GenericEventExecutorChooser implements EventExecutorChooser { @Override public EventExecutor next() { return children[Math.abs(childIndex.getAndIncrement() % children.length)]; } }
这里并不是随机获取线程
参考资料:Netty系列之Netty线程模型
-----------------------------------------------如有错误请指正------------------------------