Closed tydldd closed 8 years ago
config.setMaxTotal(50); // 最大空闲连接数, 默认8个 config.setMaxIdle(getPropertyInt(props, "redis.maxIdle")); // 默认-1 config.setMaxWaitMillis(10000); // 逐出连接的最小空闲时间 默认1800000毫秒(30分钟), 设置成3分钟 config.setMinEvictableIdleTimeMillis(180000);
// 在获取连接的时候检查有效性, 默认false
config.setTestOnBorrow(false);
// 在空闲时检查有效性, 默认false
config.setTestWhileIdle(true);
// 逐出扫描的时间间隔(毫秒) 如果为负数,则不运行逐出线程, 默认-1,设置2分钟
config.setTimeBetweenEvictionRunsMillis(10000);
服务在云上,每4分钟被切断一次长连接。现在的问题似乎是空闲检查的心跳没起作用
超时的异常发一下?
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool at redis.clients.util.Pool.getResource(Pool.java:50) at redis.clients.jedis.JedisPool.getResource(JedisPool.java:86) at com.wandoulabs.jodis.RoundRobinJedisPool.getResource(RoundRobinJedisPool.java:276) at com.datatang.api.database.redisjava.JodisTemplate.hgetall(JodisTemplate.java:92) at com.datatang.api.accesscontrol.server.access.updatedata.UpdateApiData2Mongodb$StartUpdate.run(UpdateApiData2Mongodb.java:64) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: java.util.NoSuchElementException: Timeout waiting for idle object at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:449) at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) at redis.clients.util.Pool.getResource(Pool.java:48)
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object 这个说明是从pool获取对象超时了。和网络连接没有关系。是不是你从pool拿对象后用完了没close?
jodis没有关闭api吧
jodis底层就是jedis,api是一样的。getResource拿到的Jedis对象用完了要执行close,和直接用JedisPool的用法是一样的
原来用JedisPool确实是有pool.returnResourceObject(redis);,用jodis没发现相似的方法
returnResourceObject是旧版jedis的用法,新版jedis一律使用Jedis.close
好。我试试
用了jodis,配置JedisPoolConfig后总是超时。原来用的jedis,JedisPoolConfig的配置没有变,用jedis不超时。