Netty handler,我们应该在覆盖时编写super.channelRead(),它的工作是什么?


public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    super.channelRead(ctx, msg);
    //write our own code here
}

我们是否应该写super.channelRead?为什么呢?

Whether should we write super.channelRead?

这要看情况。ChannelInboundHandlerAdapter 中 channelRead 的默认行为是将 msg 转发到下一个ChannelInboundHandler 。如果没有其他处理程序关心msg,那么就没有必要调用它。

最新更新