美文网首页
第 7 章 EventLoop 和线程模型

第 7 章 EventLoop 和线程模型

作者: FaDeo_O | 来源:发表于2017-12-18 20:28 被阅读0次
  1. EventLoop——事件循环,扩展了ScheduledExecutorService,可以提供JDK的所有方法,如scheduleAtFixedRate,schedule

    image.png
  2. 异步传输

    • EventLoop中维护着自己的任务队列,如果当前线程是分配给当前Channel以及它的EventLoop的那一个线程(通过调用EventLoopinEventLoop(Thread)),则会立即执行;否则放入内部队列,当EventLoop下次处理它的事件时,他会执行队列中的那些任务/事件 。对于长时间执行的任务建议用一个专门的EventExecutor处理
      image.png
    • 创建EventLoopGroup时就直接分配了EventLoop(以及支撑它们的Thread),以确保在需要时它们是可用的。EventLoopGroup负责为每个新创建的Channel分配一个EventLoop,同一个EventLoop可能会被分配给多个ChannelChannel的整个生命周期与EventLoop绑定(n:1),ThreadLocal变量在同一个EventLoopChannel中是共用的
      image.png
  3. 阻塞传输的EventLoopChannel是一一对应绑定

    image.png

相关文章

网友评论

      本文标题:第 7 章 EventLoop 和线程模型

      本文链接:https://www.haomeiwen.com/subject/dmltwxtx.html