在项目中出现了使用jedisPool却拿不到jedis的问题,
最后发现是因为从jedisPool中拿出去的实例没有被送回连接池
编写代码测试一下(按理说应该是关闭之后可以重复使用所以能够拿到15次)
但是结果却有点意外
代码
public class JedisUtils {
private static JedisPoolConfig poolConfig = null;
private static JedisPool jedisPool = null;
private static Integer maxTotal = null;
private static Integer maxIdle = null;
private static String host = null;
private static Integer port = null;
static{
//设置上限10个
maxTotal = Integer.parseInt("10");
maxIdle = Integer.parseInt("10");
port = Integer.parseInt("6379");
host = "localhost";
poolConfig = new JedisPoolConfig();
poolConfig.setMaxTotal(maxTotal);
poolConfig.setMaxIdle(maxIdle);
//设置等待获取连接实例(10秒)
poolConfig.setMaxWaitMillis(10000);
jedisPool = new JedisPool(poolConfig,host,port);
}
public static Jedis getJedis(){
Jedis jedis = jedisPool.getResource();
return jedis;
}
//

最低0.47元/天 解锁文章
364





