·遇到错误java.nio.channels.ClosedChannelException无限弹出,要考虑两种原因
第一种: 用户一直F5刷新,导致服务端崩溃 解决: 一:限流 二:让服务端在写数据之前判断一下channel是否已关闭。代码如下:
if (!channel.isConnected()) {
if (logger.isWarnEnabled()) {
logger.warn("Failed to write any response because the channel is not connected any more. Maybe the client has closed the connection? ");
}
return;
}
第二种:
Zookeeper客户端未连接或手动关闭了链接,检查一下自己的客户端是否开启,如果测试阶段,多半是这个问题!


