netty源码分析 之十三 线程模型
2017-01-21 19:12
986 查看
通过代码来看,netty server有两个线程池来组成 而 netty client端有一个线程池来
// Configure the server.
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc()));
}
//p.addLast(new LoggingHandler(LogLevel.INFO));
p.addLast(new EchoServerHandler());
}
});
// Start the server.
ChannelFuture f = b.bind(PORT).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();
}
}
代码解读
下面有两个线程池 bossGroup workerGroup// Configure the server.
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc()));
}
//p.addLast(new LoggingHandler(LogLevel.INFO));
p.addLast(new EchoServerHandler());
}
});
// Start the server.
ChannelFuture f = b.bind(PORT).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();
}
}
线程代码
看其代码可以看出,将workerGroup线程池,交给ServerBootstrapAcceptor线程模型
相关文章推荐
- 【Netty源码分析】Reactor线程模型
- Netty学习之旅------再谈线程模型之源码分析NioEventLoopGroup、SingleThreadEventExecutor
- 【Netty源码分析】Reactor线程模型
- Netty5源码分析(二) -- 线程模型分析
- Netty线程模型源码分析之NioEventLoopGroup的初始化
- [netty源码分析]--EventLoopGroup与EventLoop 分析netty的线程模型
- Netty源码分析之Reactor线程模型
- 【图灵学院09】RPC底层通讯原理之Netty线程模型源码分析
- 【Netty源码分析】Reactor线程模型
- Netty线程模型、Future、Channel总结和源码分析
- (转载)Memcached源码分析(线程模型)
- 线程资源PHP源码分析之线程安全模型
- ZMQ源码分析(二)-- 网络&线程模型
- Memcached源码分析(线程模型)
- EventBus源码分析(四):线程模型分析(2.4版本)
- memcached源码分析之线程模型
- Memcached源码分析(线程模型)
- EventBus源码解读详细注释(2)MainThread线程模型分析
- Memcached源码分析之线程模型
- Memcached源码分析(线程模型)