netty5.0之EventLoop

本文详细介绍了Netty框架中的核心组件EventLoop及其相关接口的作用与功能。包括EventLoop的职责、如何处理I/O操作及非I/O任务、定时任务执行等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


1、EventExecutorGroup使用它的next()方法负责提供EventExecutor,除此之外,负责生命周期的任务处理,允许以全局方式关闭所有任务(The EventExecutorGroup is responsible to provide EventExecutor's to use via its next() method. Beside this it also is responsible to handle their live-cycle and allows to shut them down in a global fashion.)

public interface EventExecutorGroup extends ScheduledExecutorService {}


2、

EventLoopGroup 继承自EventExecutorGroup, 并提供EventLoop的生成方法next()Special EventExecutorGroup which allows to register Channel's that get processed for later selection during the event loop.

public interface EventLoopGroup extends EventExecutorGroup {
    @Override
    EventLoop next();
}
3、 EventLoop的英文解释是:Will handle all the I/O-Operations for a Channel once it was registered,即处理channel的io操作( Will handle all the I/O-Operations for a  Channel  once it was registered. One  EventLoop  instance will usually handle more then one  Channel  but this may depend on implementation details and internals.

public interface EventLoop extends EventExecutor, EventLoopGroup {
    @Override
    EventLoopGroup parent();

    @Override
    EventLoop next();

    /**
     * Creates a new default {@link ChannelHandlerInvoker} implementation that uses this {@link EventLoop} to
     * invoke event handler methods.
     */
    ChannelHandlerInvoker asInvoker();
}

EventLoop 首先是一个Executor,任务执行器。  再者它本身是一个环,能够负载均衡执行压力。可以说EventLoop是Netty的一个核心,整个Netty的运转都是围绕着它。( http://www.cxyclub.cn/n/36389/)

EventLoop还继承了EventExecutor,下面看看吧

4、EventExecutor 是一个特殊的EventExecutorGroup,提供了检测一个线程是否在eventLoop中被执行之类的方法.
The EventExecutor is a special EventExecutorGroup which comes with some handy methods to see if a Thread is executed in a event loop. Beside this it also extends the EventExecutorGroup to allow a generic way to access methods.)

public interface EventExecutor extends EventExecutorGroup{}


从这些方法,我们可以清晰的认识到EventLoop可以实现以下功能: 
1. 执行任务(IO/非IO任务) 
2. 将Channel绑定到EventLoop上 
3. 执行定时任务 
4. 关闭任务 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值