BUG是这两天才出现的,程序运行的好好的,然后突然就出现redis的错误信息了,百度了很久,什么文章都看过了,终于尝试出了一个可行的办法
public Jedis getJedis(){
/* try{
return pool.getResource();
}catch(Exception ex){
logger.error("异常");
logger.error(ex.getMessage(), ex);
return null;
}*/
int timeoutCount = 0;
while (true) // 如果是网络超时则多试几次
{
try
{
Jedis jedis = pool.getResource();
return jedis;
} catch (Exception e)
{
// 底层原因是SocketTimeoutException,不过redis已经捕捉且抛出JedisConnectionException,不继承于前者
if (e instanceof JedisConnectionException || e instanceof SocketTimeoutException)
{
timeoutCount++;
logger.error("getJedis timeoutCount={}"+timeoutCount);
if (timeoutCount > 3)
{
break;
}
}else
{
logger.warn(", NumIdle="
+ pool.getNumIdle() + ", NumWaiters="
+ pool.getNumWaiters() + ", isClosed="
+ pool.isClosed());
logger.error("getJedis error", e);
break;
}
}
}
return null;
}