Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Server startup of netty source code analysis

Shulou Source: shulou.com Published: 2022-06-03 05:55:13 09月18日 Update

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

Tags: Service configuration function thread code that is underlying method end event process property port reflection source code analysis next customer factory two Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Apple Xiaomi Redmi MariaDB