我们在用jredis连接池连接redis时,连接池设置了1000以上,可是过没多久,就报无连接可用了,抛出异常。
后来网上找了些资料,在接口中发现有申请连接对象,也有释放回收对象的接口,可是,在使用过程中,我们通常只是申请对象,却忘了回收对象,就导致连接对象很快用完了。下面这边文章有对几个接口做了一些分析。
http://jiangwenfeng762.iteye.com/blog/1280700
今天想写的是,jredis的连接池是继承了apache的容器,上面那篇文章有讲到。
public void returnObject(T obj) throws Exception
-
Returns an object instance to the pool.
If
maxIdle
is set to a positive value and the number of idle instances has reached this value, the returning instance is destroyed.If
testOnReturn
== true, the returning instance is validated before being returned to the idle instance pool. In this case, if validation fails, the instance is destroyed.
这是apache官方文档,关于回收对象接口的一部分描述,所以大家在使用过程中主动回收对象是非常关键的。