You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Tony Liu <tl...@geminimobile.com> on 2009/04/24 03:58:24 UTC

Issues when using the Apache Commons Pool with testWhileIdle preperty and validateObject(Object obj) method

Hi

 

       I'm a java developer. I am now using Apache Commons Pool 1.4. I
encounter the following problems. I use PoolableObjectFactory and
GenericObjectPool. The configuration for GenericObjectPool is: 

 

       <bean id="pool"
class="org.apache.commons.pool.impl.GenericObjectPool" singleton="true">

              <property name="factory" ref="factory" />

              <property name="maxActive"><value>2</value></property>

              <property name="maxIdle"><value>-1</value></property>

              <property
name="minEvictableIdleTimeMillis"><value>-1</value></property>

              <property
name="timeBetweenEvictionRunsMillis"><value>60000</value></property>

              <property name="testWhileIdle"><value>true</value></property>

              <property name="testOnBorrow"><value>false</value></property>

              <property name="testOnReturn"><value>false</value></property>

              <property
name="numTestsPerEvictionRun"><value>-1</value></property>

       </bean> 

 

I want to validate the idle objects using the method validateObject(Object
obj) of PoolableObjectFactory. In my configuration, when I get 1 connection
from the pool and return it to the pool, the idle object should 1. And every
1 minutes, the validateObject(Object obj) should call once. The fact is in
every minutes, the validateObject(Object obj) called times will increase 1.
Also, I found that the return value of method getNumIdle() will increase 1
every time I call it the method validateObject(Object obj), while the return
value of method getNumActive() will increase negative 1. But I think, the
return value of getNumIdle() should be 1 and the return value of
getNumActive should be 0 in this situation. How could I ensure
validateObject(Object obj) just call once every minutes in this situation?

 

Could you help me?

 

 

Thanks

Tony

Gemini Mobile Technologies