最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Netty源碼解析NioEventLoop創(chuàng)建的構(gòu)造方法

 更新時(shí)間:2022年03月25日 15:37:22   作者:向南是個(gè)萬人迷  
這篇文章主要介紹了Netty源碼解析NioEventLoopGroup之NioEventLoop創(chuàng)建的構(gòu)造方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

前文傳送門:Netty源碼分析 NioEventLoop

NioEventLoopGroup之NioEventLoop的創(chuàng)建

回到上一小節(jié)的MultithreadEventExecutorGroup類的構(gòu)造方法:

protected MultithreadEventExecutorGroup(int nThreads, Executor executor, 
                                        EventExecutorChooserFactory chooserFactory, Object... args) {
    //代碼省略
    if (executor == null) {
        //創(chuàng)建一個(gè)新的線程執(zhí)行器(1)
        executor = new ThreadPerTaskExecutor(newDefaultThreadFactory());
    }
    //構(gòu)造NioEventLoop(2)
    children = new EventExecutor[nThreads];
    for (int i = 0; i < nThreads; i ++) {
        boolean success = false;
        try {
            children[i] = newChild(executor, args);
            success = true;
        } catch (Exception e) {
            throw new IllegalStateException("failed to create a child event loop", e);
        } finally {
           //代碼省略
        }
    }
    //創(chuàng)建線程選擇器(3)
    chooser = chooserFactory.newChooser(children);
    //代碼省略
}

我們來看第二步構(gòu)造NioEventLoop

這里通過 children = new EventExecutor[nThreads] 初始化了children屬性, 看下這個(gè)屬性的定義:

private final EventExecutor[] children

這里的children是EventExecutor類型的數(shù)組, 其實(shí)就是NioEventLoop的集合, 因?yàn)镹ioEventLoop也是EventExecutor的子類

所以這里初始化了children數(shù)組, 大小為參數(shù)nThreads傳入的線程數(shù)量, 默認(rèn)為cpu核數(shù)的兩倍

后面就是通過for循環(huán)來創(chuàng)建NioEventLoop線程,

在循環(huán)體里通過 children[i] = newChild(executor, args) 創(chuàng)建NioEventLoop, 我們跟newChild(executor, args)方法

因?yàn)槭荖ioEventLoopGroup調(diào)用的,所以跟到NioEventLoop的newChild方法中:

protected EventLoop newChild(Executor executor, Object... args) throws Exception {
    return new NioEventLoop(this, executor, (SelectorProvider) args[0], 
        ((SelectStrategyFactory) args[1]).newSelectStrategy(), (RejectedExecutionHandler) args[2]);
}

這里我們看到創(chuàng)建了一個(gè)NioEventLoop對(duì)象, 其中this是NioEventLoopGroup自身, executor就是上一小節(jié)講到的線程執(zhí)行器

我們繼續(xù)跟到NioEventLoop的構(gòu)造方法

NioEventLoop(NioEventLoopGroup parent, Executor executor, SelectorProvider selectorProvider, 
             SelectStrategy strategy, RejectedExecutionHandler rejectedExecutionHandler) {
    super(parent, executor, false, DEFAULT_MAX_PENDING_TASKS, rejectedExecutionHandler);
    //代碼省略
    provider = selectorProvider;
    selector = openSelector();
    selectStrategy = strategy;
}

首先看到了調(diào)用了父類的構(gòu)造方法, 然后初始化了幾個(gè)屬性:

 selector = openSelector() 這種方式創(chuàng)建個(gè)NioEventLoop綁定的selector對(duì)象, 有關(guān)創(chuàng)建過程, 之后會(huì)講到

跟進(jìn)父類SingleThreadEventLoop類構(gòu)造方法:

protected SingleThreadEventLoop(EventLoopGroup parent, Executor executor, 
                                boolean addTaskWakesUp, int maxPendingTasks, 
                                RejectedExecutionHandler rejectedExecutionHandler) {
    super(parent, executor, addTaskWakesUp, maxPendingTasks, rejectedExecutionHandler);
    tailTasks = newTaskQueue(maxPendingTasks);
}

再跟到父類SingleThreadEventExecutor構(gòu)造方法:

protected SingleThreadEventExecutor(EventExecutorGroup parent, Executor executor, 
                                    boolean addTaskWakesUp, int maxPendingTasks, 
                                    RejectedExecutionHandler rejectedHandler) {
    super(parent);
    this.addTaskWakesUp = addTaskWakesUp;
    this.maxPendingTasks = Math.max(16, maxPendingTasks);
    this.executor = ObjectUtil.checkNotNull(executor, "executor");
    taskQueue = newTaskQueue(this.maxPendingTasks);
    rejectedExecutionHandler = ObjectUtil.checkNotNull(rejectedHandler, "rejectedHandler");
}

 this.executor = ObjectUtil.checkNotNull(executor, "executor") 

這里初始化了線程執(zhí)行器

 taskQueue = newTaskQueue(this.maxPendingTasks) 

是創(chuàng)建一個(gè)任務(wù)隊(duì)列, 這個(gè)任務(wù)隊(duì)列可以將不屬于NioEventLoop線程的任務(wù)放到這個(gè)任務(wù)隊(duì)列中, 通過NioEventLoop線程執(zhí)行, 具體使用場(chǎng)景之后我們會(huì)看到

跟到父類AbstractScheduledEventExecutor的構(gòu)造方法中:

protected AbstractScheduledEventExecutor(EventExecutorGroup parent) {
    super(parent);
}

最后跟到AbstractEventExecutor類的構(gòu)造方法

protected AbstractEventExecutor(EventExecutorGroup parent) {
    this.parent = parent;
}

這里初始化了parent, 這個(gè)parent就NioEventLoop所屬的線程組NioEventLoopGroup對(duì)象

至此, NioEventLoop創(chuàng)建完成

以上就是Netty源碼解析NioEventLoop創(chuàng)建的構(gòu)造方法的詳細(xì)內(nèi)容,更多關(guān)于Netty NioEventLoop構(gòu)造方法的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • 淺談Spring裝配Bean之組件掃描和自動(dòng)裝配

    淺談Spring裝配Bean之組件掃描和自動(dòng)裝配

    本篇文章主要介紹了淺談Spring裝配Bean之組件掃描和自動(dòng)裝配,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-10-10
  • java -jar啟動(dòng)項(xiàng)目以及日志輸出的相關(guān)問題

    java -jar啟動(dòng)項(xiàng)目以及日志輸出的相關(guān)問題

    這篇文章主要介紹了java -jar啟動(dòng)項(xiàng)目以及日志輸出的相關(guān)問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-04-04
  • java中方法遞歸的簡(jiǎn)單示例

    java中方法遞歸的簡(jiǎn)單示例

    這篇文章主要給大家介紹了關(guān)于java中方法遞歸的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-12-12
  • java多線程編程之向線程傳遞數(shù)據(jù)的三種方法

    java多線程編程之向線程傳遞數(shù)據(jù)的三種方法

    在多線程的異步開發(fā)模式下,數(shù)據(jù)的傳遞和返回和同步開發(fā)模式有很大的區(qū)別。由于線程的運(yùn)行和結(jié)束是不可預(yù)料的,因此,在傳遞和返回?cái)?shù)據(jù)時(shí)就無法象函數(shù)一樣通過函數(shù)參數(shù)和return語(yǔ)句來返回?cái)?shù)據(jù)
    2014-01-01
  • Java 停止線程需要注意的地方

    Java 停止線程需要注意的地方

    這篇文章主要介紹了Java 停止線程需要注意的地方,幫助大家更好的理解和學(xué)習(xí)Java線程的相關(guān)資料,感興趣的朋友可以了解下
    2020-09-09
  • springboot中使用mybatisplus自帶插件實(shí)現(xiàn)分頁(yè)的示例代碼

    springboot中使用mybatisplus自帶插件實(shí)現(xiàn)分頁(yè)的示例代碼

    這篇文章主要介紹了springboot中使用mybatisplus自帶插件實(shí)現(xiàn)分頁(yè),本文通過示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-09-09
  • 基于Java的度分秒坐標(biāo)轉(zhuǎn)純經(jīng)緯度坐標(biāo)的漂亮國(guó)基地信息管理的方法

    基于Java的度分秒坐標(biāo)轉(zhuǎn)純經(jīng)緯度坐標(biāo)的漂亮國(guó)基地信息管理的方法

    本文以java語(yǔ)言為例,詳細(xì)介紹如何管理漂亮國(guó)的基地信息,為下一步全球的空間可視化打下堅(jiān)實(shí)的基礎(chǔ),首先介紹如何對(duì)數(shù)據(jù)進(jìn)行去重處理,然后介紹在java當(dāng)中如何進(jìn)行度分秒位置的轉(zhuǎn)換,最后結(jié)合實(shí)現(xiàn)原型進(jìn)行詳細(xì)的說明,感興趣的朋友跟隨小編一起看看吧
    2024-06-06
  • 解決resultMap映射數(shù)據(jù)錯(cuò)誤的問題

    解決resultMap映射數(shù)據(jù)錯(cuò)誤的問題

    這篇文章主要介紹了解決resultMap映射數(shù)據(jù)錯(cuò)誤的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-08-08
  • SpringMVC和Swagger整合方法

    SpringMVC和Swagger整合方法

    Swagger 是一個(gè)規(guī)范和完整的框架,用于生成、描述、調(diào)用和可視化 RESTful 風(fēng)格的 Web 服務(wù)。下面通過本文給大家分享SpringMVC和Swagger整合方法,感興趣的朋友一起看看吧
    2017-08-08
  • Mybatis order by 動(dòng)態(tài)傳參出現(xiàn)的問題及解決方法

    Mybatis order by 動(dòng)態(tài)傳參出現(xiàn)的問題及解決方法

    今天,我正在愉快地CRUD,突然發(fā)現(xiàn)出現(xiàn)一個(gè)Bug,我們來看看是怎么回事吧!接下來通過本文給大家介紹Mybatis order by 動(dòng)態(tài)傳參出現(xiàn)的一個(gè)小bug,需要的朋友可以參考下
    2021-07-07

最新評(píng)論

南开区| 璧山县| 甘孜| 望奎县| 五原县| 五华县| 虹口区| 略阳县| 逊克县| 贵定县| 呼伦贝尔市| 土默特左旗| 永修县| 南江县| 石柱| 青州市| 呼图壁县| 青河县| 湘潭县| 文山县| 玛纳斯县| 福清市| 松潘县| 玛沁县| 棋牌| 苏尼特左旗| 江陵县| 德阳市| 琼结县| 延庆县| 大连市| 磴口县| 固安县| 文安县| 青海省| 科技| 静宁县| 永靖县| 洛扎县| 永川市| 松溪县|