Netty study notes (4) ------ EventLoopGroup

EventLoopGroup responsible for managing the Channel event processing tasks, inherited from java.util.concurrent package adds Executor, so its structure is similar to the thread pool, manage multiple EventLoop.
And a EventLoop will never change Thread a drive, while the task (Runnable or Callable) can be submitted directly to EventLoop achieve.
Further, a EventLoop may be assigned for a plurality of services Channel, Channel corresponding I / O event (binding or it ChannelHandler processor) by the EventLoop of Thread processing.

EventLoop distribution

Asynchronous Transfer (NIOEventloopGroup)


EventLoopGroup responsible for each newly created Channel assign a EventLoop, currently polling allocation algorithm. EventLoop may be assigned to a plurality Channel.
The life cycle of a Channel uses the same EventLoop handle the event, which means that only deal with a change in status Channel without worrying about its thread-safety issues. Multi-Channel sharing but for ThreaLocal to consider.

Synchronous transmission (OIOEventLoopGroup)


Transmitted synchronously with the difference that a EventLoop asynchronous transmission can be assigned to a Channel.

EventLoop flow processing tasks


If the current thread is EventLoop thread, then the task will be executed directly; if not, the task will enter the internal queue EventLoop (EventLoop each has its own queue, unlike the thread pool).
As the Channel events by specific thread, so long task or tasks do not put in the blocking process EventLoop, or will block other tasks on the EventLoop. Netty authors recommend the use of a special Executor process.

Reference material

Netty in action

Guess you like

Origin www.cnblogs.com/wuweishuo/p/10993843.html