netty 推荐版本netty-all-4.1.5.Final
netty 推荐地址https://my.oschina.net/7001?tab=newest&catalogId=3727357,多篇文章
内存模型:reactor模式,单线程(单reactor线程(多路复用)完成acceptor,dispatcher事件分发,handler处理) 如下workerGroup为bossGroup
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup)
.channel(NioServerSocketChannel.class)
......
多线程(单reactor线程acceptor,线程池handler,一般建立的链路会绑定到某个handler线程,避免并发)
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
......
主从(线程池acceptor,线程池handler)
EventLoopGroup bossGroup = new NioEventLoopGroup(4);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
无锁化设计:每个Channel绑定唯一的EventLoop,这意味着同一个Channel生命周期内的所有事件都将由同一个Reactor线程来完成
Reactor线程除了处理IO事件外,还配备了一个task队列(系统任务)和Delay task队列(周期任务)
EventLoop EventExecutor EventLoopGroup EventExecutorGroup 接口关系:
1.Loop extends Executor
2 Group 聚合单个:即EventLoopGroup内含多个EventLoop,next()方法选择单个由它完成具体任务
3 Executor extends ExecutorGroup ,Loop extends LoopGroup ,代表提交到Group的请求由单个来完成,因此单个拥有group的能力
EventExecutor 特殊方法:inEventLoop 识别某个线程(无参数为当前线程)是否是EventExecutor 内置线程