Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not get a resource from the pool Timeout waiting for idle object #4

Closed
tydldd opened this issue Nov 20, 2015 · 8 comments
Closed

Comments

@tydldd
Copy link

tydldd commented Nov 20, 2015

问题:
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

@Apache9
Copy link
Member

Apache9 commented Nov 20, 2015

“消耗完”具体是指什么操作?是比如你设置连接数最大是200,你只要操作200次就一定会挂?还是说跑了一段时间就挂了,并没有统计总共操作了多少次?

谢谢

@tydldd
Copy link
Author

tydldd commented Nov 20, 2015

定时任务,一段时间内取出200个redis实例,第201次就报错了

@Apache9
Copy link
Member

Apache9 commented Nov 20, 2015

单线程顺序执行吗?

@tydldd
Copy link
Author

tydldd commented Nov 20, 2015

@Apache9
Copy link
Member

Apache9 commented Nov 21, 2015

确认一下你依赖的jedis的版本?jodis引入的jedis应该是2.6+的,这个版本以后的jedis才可以通过直接close来归还连接,之前的版本不行。

谢谢

@tydldd
Copy link
Author

tydldd commented Nov 23, 2015

jedis版本是2.7.2的

@tydldd
Copy link
Author

tydldd commented Nov 23, 2015

jodis是0.2.1

@Apache9
Copy link
Member

Apache9 commented Nov 23, 2015

那这比较奇怪了,这是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();
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants