标签:style blog io color ar os 使用 java for
redis使用连接池报错解决
redis使用十几小时就一直报异常
redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool at redis.clients.util.Pool.getResource(Pool.java:22) at com.derbysoft.jredis.longkeytest.BorrowObject.run(BorrowObject.java:22) at java.lang.Thread.run(Thread.java:662) Caused by: java.util.NoSuchElementException: Timeout waiting for idle object at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1134) at redis.clients.util.Pool.getResource(Pool.java:20)
原因是没有回收资源导致
正确的做法是
ShardedJedis jedis = shardedJedisPool.getResource(); try { jedis.set(key, value); } finally { shardedJedisPool.returnResource(jedis); }
标签:style blog io color ar os 使用 java for
原文地址:http://www.cnblogs.com/gisblogs/p/4076285.html