According to the New and Noteworthy document in 4.0 , netty4 provided the new bootstrap API, and the document gives the following code example:
public static void main(String[] args) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.localAddress(8080)
.childOption(ChannelOption.TCP_NODELAY, true)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(handler1, handler2, ...);
}
});
ChannelFuture f = b.bind().sync();
f.channel().closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
bossGroup.terminationFuture().sync();
workerGroup.terminationFuture().sync();
}
}
The code is used ServerBootStrap.optionfor installation ChannelOption.SO_BACKLOG, and then used ServerBootStrap.childOptionfor installation ChannelOption.TCP_NODELAY.
What is the difference between ServerBootStrap.optionand ServerBootStrap.childOption? How can I find out which parameter should be optionand which should be childOption?
source
share