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);
}
网友评论