问题出现的原因:
长时间很频繁的对redis进行读或者写的操作时,会出现“Could not get a resource from the pool”的错误。
出现此错误后,“Jedis jedis = jedisPool.getResource()”中的jedisPool已经无法从连接池中再获取jedis资源对象,就导致池中无可用资源,所以会出现无法获取新的资源。
解决方法:
Jedis 对象用完以后一定要释放掉,这样才能获取新的资源。
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
linkList = jedis.lrange(RECOMMEND_KEY, 0, -1);
} catch (Exception e) {
e.printStackTrace();
} finally {
//释放资源
jedisPool.returnResource(jedis);
}