Netty in Action笔记(Chapter 9)Bootstraping Netty applications

EventLoop and EventLoopGroup
Remember the EventLoop that is assigned to the Channel is responsible to handle all the operations for the Channel. Which means whenever you execute a method that returns a ChannelFuture it will be executed in the EventLoop that is assigned to the Channel.
The EventLoop is executed by the Thread that is bound to it.
The EventLoopGroup contains a number of EventLoops and is responsible to assign an EventLoop to the Channel during its registration.

Why share the EventLoop ?
When you share the EventLoop you can be sure all Channels that are assigned to the EventLoop are using the same Thread. Remember an EventLoop is assigned to a Thread which execute the operations of it.
Because of using the same Thread there is no context-switching envolved and thus less overhead.

【9.6 Using Netty ChannelOptions and attributes】

评论

暂无评论