1. 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模式進行闡述

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

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

        • Doug Lea三種模式

        單線程

        多線程 Reactor

        Multiple Reactor

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

        Netty 和 Reactor 的模式同時都支持的


        • 單線程的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使用線程池進行處理

        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里面有一個EventExecutor數(shù)組,保存了多個EventExecutor;

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

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

        喜歡,在看


        瀏覽 57
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        分享
        舉報
        評論
        圖片
        表情
        推薦
        點贊
        評論
        收藏
        分享

        手機掃一掃分享

        分享
        舉報
          
          

            1. 国产一级A片免费视频 | 久久久天堂国产精品女人 | 美女视频黄a视频全免费观看 | 男女午夜免费视频 | 国产精品自在线 |