Netty4(一)NioEventLoopGroup

Netty4(一)NioEventLoopGroup

先看默认构造方法
public NioEventLoopGroup() {
this(0);
}
有参构造方法
public NioEventLoopGroup(int nThreads) {
this(nThreads, (Executor)null);
}

public NioEventLoopGroup(int nThreads, Executor executor) {
//获得了Selector提供器
this(nThreads, executor, SelectorProvider.provider());
}

public NioEventLoopGroup(int nThreads, Executor executor, SelectorProvider selectorProvider) {
this(nThreads, executor, selectorProvider, DefaultSelectStrategyFactory.INSTANCE);
}

public NioEventLoopGroup(int nThreads, Executor executor, SelectorProvider selectorProvider, SelectStrategyFactory selectStrategyFactory) {

super(nThreads, executor, new Object[]{selectorProvider, selectStrategyFactory, 
//拒绝策略
RejectedExecutionHandlers.reject()});
}
//这个就是上面那个默认拒绝策略
private static final RejectedExecutionHandler REJECT = new RejectedExecutionHandler() {
public void rejected(Runnable task, SingleThreadEventExecutor executor) {
throw new RejectedExecutionException();
}
};
接着就是这个构造方法
最后到MultithreadEventExecutorGroup
protected MultithreadEventLoopGroup(int nThreads, Executor executor, Object... args) {
super(nThreads == 0 ? DEFAULT_EVENT_LOOP_THREADS : nThreads, executor, args);
}
这个就是默认线程池个数最小1个最大内核数的2倍

private static final int DEFAULT_EVENT_LOOP_THREADS = Math.max(1, SystemPropertyUtil.getInt("io.netty.eventLoopThreads", NettyRuntime.availableProcessors() * 2));
executor = new ThreadPerTaskExecutor(this.newDefaultThreadFactory());
this.children = new EventExecutor[nThreads];
this.children[i] = this.newChild((Executor)executor, args);