Server startup of netty source code analysis
ServerBootstrap and Bootstrap are the boot classes of server and client in netty respectively, which are mainly responsible for initialization, configuration and boot of server and client. Then we will make a simple analysis of the source code of ServerBootstrap and Bootstrap through the examples in netty source code. First of all, we know that both classes inherit from the AbstractBootstrap class
Then we will start with an example of ServerBootstrap in the netty source code to make a simple analysis of it.
/ / Configure the server.
EventLoopGroup bossGroup = new NioEventLoopGroup (1)
EventLoopGroup workerGroup = new NioEventLoopGroup ()
Final EchoServerHandler serverHandler = new EchoServerHandler ()
Try {
/ / initialize a server boot class
ServerBootstrap b = new ServerBootstrap ()
B.group (bossGroup, workerGroup) / / set thread group
The IO model of .channel (NioServerSocketChannel.class) / / sets ServerSocketChannel is divided into epoll and Nio
.option (ChannelOption.SO_BACKLOG, 100) / / set the option parameter and save it as a LinkedHashMap