zoukankan      html  css  js  c++  java
  • Netty-EventLoop

    1. public interface EventLoop extends EventExecutor, EventLoopGroup

    2. public interface EventExecutor extends EventExecutorGroup

    3. public interface EventExecutorGroup extends ScheduledExecutorService, Iterable<EventExecutor>

    4. public interface ScheduledExecutorService extends ExecutorService

    5. public interface ExecutorService extends Executor

    public abstract class SingleThreadEventLoop extends SingleThreadEventExecutor implements EventLoop

    EventLoop 其实就是 Executor,也就是一个线程池。对于执行器来说,它可以有多个线程,也可以有一个线程。

    ExecutorService 通过对外暴露接口,将要执行的任务放在任务队列中,执行器中的线程会从队列中拿走任务去执行,

    将结果返回。

    public final class NioEventLoop extends SingleThreadEventLoop

    @Override
     protected EventExecutor newChild(
                ThreadFactory threadFactory, Object... args) throws Exception {
            return new NioEventLoop(this, threadFactory, (SelectorProvider) args[0]);
     }
    

      Netty 中使用了只拥有一个的线程的线程池 EventExecutor, 也就是在 new NioEventLoopGroup( count ) 时,其实创建的 count 个 线程池,这些线程池

    里面也只有一个线程。结果就是创建了 count 个线程,然后就就是 将线程池和Channel绑定一起来,这样的结果就是 channel 的操作永远是在相同的一个线程

    里被执行。

  • 相关阅读:
    最大子序列和问题之算法优化
    数据揭秘:低学历成功逆袭概率有多少?感谢父母送我读书!
    据说这份高考卷,只有程序员能得满分!
    牛客OI赛制测试赛2
    斯特林公式
    N!的近似值_斯特林公式
    矩阵快速幂
    回文树
    回文树入门
    环和链的判断
  • 原文地址:https://www.cnblogs.com/iiiDragon/p/9602951.html
Copyright © 2011-2022 走看看