美文网首页
netty 心跳检测机制

netty 心跳检测机制

作者: 奔跑吧老王 | 来源:发表于2020-04-09 10:13 被阅读0次

IdleStateHandler是netty默认处理心跳的处理类,该类需要传递4个参数

  • readerIdleTime 多长时间没有读,超过这个时间会发送一个心跳检测包检测是否存在链接
  • writerIdleTime 多长时间没有写,超过这个时间会发送一个心跳检测包检测是否存在链接
  • allIdleTime 多长时间没有读写,超过这个时间会发送一个心跳检测包检测是否存在链接
  • unit 时间单位
  • 当IdleStateEvent 触发后,会传递给下一个handler的userEventTriggered去处理
public IdleStateHandler(long readerIdleTime, long writerIdleTime, long allIdleTime, TimeUnit unit) {
        this(false, readerIdleTime, writerIdleTime, allIdleTime, unit);
    }
三个参数默认是秒
 public IdleStateHandler(int readerIdleTimeSeconds, int writerIdleTimeSeconds, int allIdleTimeSeconds) {
        this((long)readerIdleTimeSeconds, (long)writerIdleTimeSeconds, (long)allIdleTimeSeconds, TimeUnit.SECONDS);
    }

相关文章

网友评论

      本文标题:netty 心跳检测机制

      本文链接:https://www.haomeiwen.com/subject/cqelmhtx.html