異常描述: java
-
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)
-
一、產生緣由:客戶端去redis服務器拿鏈接(代碼描述的是租用對象borrowObject)的時候,池中無可用鏈接,即池中全部鏈接被佔用,且在等待時候設定的超時時間後還沒拿到時,報出此異常。
二、解決辦法:調整JedisPoolConfig中maxActive爲適合本身系統的閥值。
<bean id="dataJedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
<property name="maxActive" value="300"/>
<property name="maxIdle" value="100"/>
<property name="maxWait" value="10000"/>
<property name="testOnBorrow" value="true"/>
</bean> redis