Netty源码分析系列

Netty源码分析系列--1.NioEventLoopGroup

2018-10-25  本文已影响18人  ted005

Netty服务器开发模式

public class MyServer {

    public static void main(String[] args) throws InterruptedException {
        EventLoopGroup bossGroup = new NioEventLoopGroup();
        EventLoopGroup workerGroup = new NioEventLoopGroup();

        ServerBootstrap serverBootstrap = new ServerBootstrap();
        serverBootstrap.group(bossGroup, workerGroup)
                        .channel(NioServerSocketChannel.class)
                        .childHandler(new MyServerInitializer());

        ChannelFuture channelFuture = serverBootstrap.bind(8899).sync();
        channelFuture.channel().closeFuture().sync();

        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

NioEventLoopGroup

public NioEventLoopGroup() {
    this(0);
}

//指定线程个数
public NioEventLoopGroup(int nThreads) {
    this(nThreads, (Executor) null);
}
  1. selectorProvider: SelectorProvider.provider()
  2. selectStrategyFactory:DefaultSelectStrategyFactory.INSTANCE
  3. rejectedExecutionHandler:RejectedExecutionHandlers.reject()
上一篇 下一篇

猜你喜欢

热点阅读