EventLoop 与Channel 的关联
生活随笔
收集整理的這篇文章主要介紹了
EventLoop 与Channel 的关联
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在Netty 中, 每個Channel 都有且僅有一個EventLoop 與之關聯, 它們的關聯過程如下:
從上圖中我們可以看到,當調用AbstractChannel$AbstractUnsafe.register()方法后,就完成了Channel 和EventLoop的關聯。register()方法的具體實現如下:
public final void register(EventLoop eventLoop, final ChannelPromise promise) {// 刪除條件檢查AbstractChannel.this.eventLoop = eventLoop;if (eventLoop.inEventLoop()) {register0(promise);} else {try {eventLoop.execute(new Runnable() {@Overridepublic void run() {register0(promise);}});} catch (Throwable t) {// 刪除catch 塊內容}} }在AbstractChannel$AbstractUnsafe.register() 方法中, 會將一個EventLoop 賦值給AbstractChannel 內部的eventLoop 字段,這句代碼就是完成EventLoop 與Channel 的關聯過程。
?
總結
以上是生活随笔為你收集整理的EventLoop 与Channel 的关联的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NioEventLoop 的实例化过程
- 下一篇: EventLoop 的启动