Netty的server启动流程
2019-06-20 16:05:39 0 举报
Netty的server服务启动流程
作者其他创作
大纲/内容
new NioEventLoopGroup()
AbstractChannel # register0(ChannelPromise promise)
1
3
chooserFactory.newChooser(children)
实际上就是Group管理的线程
threadFactory.newThread(command).start();
SingleThreadEventExecutor # runAllTasks(long timeoutNanos)
AbstractNioChannel # doRegister()
将channel注册到Selector,创建SelectionKey对象
2
SingleThreadEventExecutor # execute(Runnable task)
new ThreadPerTaskExecutor(newDefaultThreadFactory())
SingleThreadEventExecutor.this.run()
Reacotor启动过程
NioEventLoop #processSelectedKeys();
executor:线程的管理类
SingleThreadEventExecutor # safeExecute(task);
NioEventLoop # processSelectedKeysOptimized();
NioEventLoop # run()
SingleThreadEventExecutor # startThread()
NioEventLoop # select(wakenUp.getAndSet(false));
Netty中对线程进行了封装。每个EventExecutor表示一个单独的线程,可以执行Runable任务,EventExecutorGroup相当于一个线程组,用于管理和分配一组EventExecutor。MultilthreadEventExecutorGroup是EventExecutorGroup的抽象实现
ThreadPerTaskExecutor # execute(Runnable command)
0 条评论
回复 删除
下一页