如何处理 jedis得连接池得异常,顺着找到Jedis的工厂类JedisFactory,对应看下这两个方法的实现,熟悉的代码找到了,可疑的点也找到了:
public boolean validateObject(PooledObject<Jedis> pooledJedis) {
final BinaryJedis jedis = pooledJedis.getObject();
try {
String host = jedisSocketFactory.getHost();
int port = jedisSocketFactory.getPort();
String connectionHost = jedis.getClient().getHost();
int connectionPort = jedis.getClient().getPort();
return host.equals(connectionHost)
&& port == connectionPort && jedis.isConnected()
&& jedis.ping().equals("PONG");
} catch (final Exception e) {
logger.error("Error while validating pooled Jedis object.", e);
return false;
}
}
删除setPoolConfig设置就可以了,除非必要,可以使用jedis默认得配置,如果修改过setTestOnBorrow得开关,就要考虑是否关掉这个开关。