I am using Apache Commons Pool 2
, I have set the configuration testWhileIdle
to true, which means that the Pool framework will check whether the idle objects they are valid.
I would ask whether this check occurs periodically, if so, what's the default interval, and how i can change it.
I ask so because the objects in the pool should periodically connect to the server to keep alive, and I think pool's validateObject
method is a good place to fulfill this.
Per @user7294900's comments,there are two configuration parameters:
timeBetweenEvictionRunsMillis
, default value is -1minEvictableIdleTimeMillis
, default value is 1800*60*30
I have following two question:
- What's the difference between these two parameters?
- I set both of them to 5000, and I have 8 objects in the pool, I print the object's hashcode in my PooledObjectFactory's
validateObject
method, I found that only 3 objects'hash code has been printed out, then there is no more messages printed again, looks thevalidateObject
's is not called every 5 seconds or the call tovalidateObject
is stuck?
I figured out the problem, please see the comments