Closed tydldd closed 8 years ago
“消耗完”具体是指什么操作?是比如你设置连接数最大是200,你只要操作200次就一定会挂?还是说跑了一段时间就挂了,并没有统计总共操作了多少次?
谢谢
定时任务,一段时间内取出200个redis实例,第201次就报错了
单线程顺序执行吗?
嗯
确认一下你依赖的jedis的版本?jodis引入的jedis应该是2.6+的,这个版本以后的jedis才可以通过直接close来归还连接,之前的版本不行。
谢谢
jedis版本是2.7.2的
jodis是0.2.1
那这比较奇怪了,这是2.7.x的jedis的close代码,看起来应该是归还了啊。
@Override
public void close() {
if (dataSource != null) {
if (client.isBroken()) {
this.dataSource.returnBrokenResource(this);
} else {
this.dataSource.returnResource(this);
}
} else {
client.close();
}
}
问题: 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:101) at com.datatang.api.accesscontrol.server.acount.updatedata.UpdateAccountData2Mongodb$StartUpdate.run(UpdateAccountData2Mongodb.java:61) 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:744) 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) ... 11 more
注释:方法里已经关闭redis连接了。 Jedis redis = pool.getResource(); Map map = redis.hgetAll(key); redis.close(); 等把pool里设置的连接数消耗完,就报上边的错误了。但是为什么redis没有返回pool里呢。 连接池使用了jodis。 codis版本2.0.7