<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Netty線程模型、源碼解析

          共 1750字,需瀏覽 4分鐘

           ·

          2021-06-13 20:09

          0x01:Reactor 模式

          Douglas C. Schmidt 1995年提出:

          An Object Behavioral Pattern for Demultiplexing and 
          Dispatching Handles for Synchronous Events

          Scalable IO in Java - Doug Lea

          http://gee.cs.oswego.edu/dl/cpjslides/nio.pdf
          基于Java IO對Reactor模式進(jìn)行闡述

          NIO 網(wǎng)絡(luò)框架的典型模式

          Mina、Netty、Cindy 都是此模式的實(shí)現(xiàn)
          • Douglas

          • Doug Lea三種模式

          單線程

          多線程 Reactor

          Multiple Reactor

          其他主從形式,但是不常用

          Netty 和 Reactor 的模式同時(shí)都支持的


          • 單線程的Reactor

          EventLoopGroup eventExecutors = new NioEventLoopGroup(1);
          ServerBootstrap serverBootstrap = new ServerBootstrap().group(eventExecutors,eventExecutors);


          • 多線程

          EventLoopGroup eventExecutors = new NioEventLoopGroup(1);
          ServerBootstrap serverBootstrap = new ServerBootstrap().group(eventExecutors,eventExecutors);//Handler使用線程池進(jìn)行處理

          Multiple Reactor

          EventLoopGroup eventExecutors = new NioEventLoopGroup(1);
          EventLoopGroup workereventExecutors = new NioEventLoopGroup();
          ServerBootstrap serverBootstrap = new ServerBootstrap().group(eventExecutors,workereventExecutors);

          EventLoopGroup eventExecutors = new NioEventLoopGroup();
          EventLoopGroup workereventExecutors = new NioEventLoopGroup();
          ServerBootstrap serverBootstrap = new ServerBootstrap().group(eventExecutors,workereventExecutors);


          0x02: 源碼

          EventExecutor視圖

          1. EventExecutorGroup里面有一個(gè)EventExecutor數(shù)組,保存了多個(gè)EventExecutor;

          2. EventExecutorGroup是不干什么事情的,當(dāng)收到一個(gè)請后,他就調(diào)用next()獲得一個(gè)它里面的EventExecutor,再調(diào)用這個(gè)executor的方法;

          3. next(): EventExecutorChooser.next()定義選擇EventExecutor的策略;

          喜歡,在看


          瀏覽 57
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  麻豆成人久久精品 | 大奶一区二区三区 | 淫色在线视频 | 久久免费高清 | 影音先锋红桃视频 |