日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

NioEventLoop 的实例化过程

發布時間:2024/4/13 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 NioEventLoop 的实例化过程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

先簡單回顧一下EventLoop 實例化的運行時序圖:

從上圖可以看到, SingleThreadEventExecutor 有一個名為thread 的Thread 類型字段, 這個字段就是與SingleThreadEventExecutor 關聯的本地線程。我們看看thread 在哪里被賦值的:?

private void doStartThread() {assert thread == null;executor.execute(new Runnable() {@Overridepublic void run() {thread = Thread.currentThread();boolean success = false;updateLastExecutionTime();try {SingleThreadEventExecutor.this.run();success = true;} catch (Throwable t) {logger.warn("Unexpected exception from an event executor: ", t);} finally {// 此處省略清理代碼}}}); }

之前的章節我們分析過,SingleThreadEventExecutor 啟動時會調用doStartThread()方法,然后調用executor.execute()方法,將當前線程賦值給thread。在這個線程中所做的事情主要就是調用SingleThreadEventExecutor.this.run()方法,而因為NioEventLoop 實現了這個方法,因此根據多態性,其實調用的是NioEventLoop.run()方法。

?

總結

以上是生活随笔為你收集整理的NioEventLoop 的实例化过程的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。