根據該文檔New and noteworthy in 4.0 ServerBootstrap.option()和ServerBootstrap.childOption()之間的差,netty4提供了一種新的自舉的API,並且該文檔給出了下面的代碼示例:是什麼在網狀4.x的
public static void main(String[] args) throws Exception {
// Configure the server.
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, ...);
}
});
// Start the server.
ChannelFuture f = b.bind().sync();
// Wait until the server socket is closed.
f.channel().closeFuture().sync();
} finally {
// Shut down all event loops to terminate all threads.
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
// Wait until all threads are terminated.
bossGroup.terminationFuture().sync();
workerGroup.terminationFuture().sync();
}
}
該代碼使用ServerBootStrap.option
來設置ChannelOption.SO_BACKLOG
,然後使用ServerBootStrap.childOption
來設置ChannelOption.TCP_NODELAY
。
ServerBootStrap.option
和ServerBootStrap.childOption
有什麼區別?我怎麼知道哪個選項應該是option
,哪個應該是childOption
?