Exception Description:
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) ...
2 more
1, the reason: the client to the Redis server to get the connection (the code describes the lease object Borrowobject), there is no connection in the pool, that is, all connections in the pool is occupied, and in the waiting time after the timeout time set to not get, reported this exception.
2, the solution: adjust the jedispoolconfig in the maxactive to suit their own system threshold.
<bean id= "Datajedispoolconfig" class= "Redis.clients.jedis.JedisPoolConfig" >
<property name= "maxactive" value= "/>"
<property name= "Maxidle" value= "/>"
<property name= "maxwait" value= "10000"/>
<property name= "Testonborrow" value= "true"/>
</bean>
3. Reproduce:
public class Borrowobject implements Runnable {
private shardedjedispool jedispool;
Public Borrowobject (Shardedjedispool jedispool) {
this.jedispool = Jedispool;
}
@Override public
Void Run () {
Shardedjedis Shardedjedis = null;
try {
Shardedjedis = Jedispool.getresource ();
String value = Shardedjedis.hget ("long_key_test:aa059e03e0ab7d806e6c351f87404b06c1190", "Roc El Pinar aparthotel");
System.out.println (value);
} catch (Exception e) {
//logger.error (e);
E.printstacktrace ();
} finally {
jedispool.returnresource (Shardedjedis);}}}
public class Borrowobjecttest {private Shardedjedispool jedispool = null;
Public Borrowobjecttest () {list<jedisshardinfo> Jedisshardinfos = new arraylist<jedisshardinfo> ();
Jedisshardinfo jedisshardinfo = new Jedisshardinfo ("192.168.1.112");
Jedisshardinfo.settimeout (1000000);
Jedisshardinfos.add (Jedisshardinfo);
Jedispool = new Shardedjedispool (Createjedisconfig (), Jedisshardinfos);
} private Jedispoolconfig Createjedisconfig () {jedispoolconfig jedisconfig = new Jedispoolconfig ();
Jedisconfig.setmaxactive (2);
Jedisconfig.setmaxidle (2);
Jedisconfig.setmaxwait (5);
Jedisconfig.settestonborrow (TRUE);
return jedisconfig;
} public static void Main (string[] args) {borrowobjecttest borrowobjecttest = new Borrowobjecttest ();
for (int i = 0; i <; i++) {New Thread (new Borrowobject (Borrowobjecttest.jedispool)). Start ();
} }
}
reprinted from: http://www.iteye.com/topic/1122212