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*30I have following two question:
validateObject
method, I found that only 3 objects'hash code has been printed out, then there is no more messages printed again, looks the validateObject
's is not called every 5 seconds or the call to validateObject
is stuck?I figured out the problem, please see the comments
You can use\update timeBetweenEvictionRunsMillis
for changing time of idle validation, see Tomcat JDBC Connection Pool.
timeBetweenEvictionRunsMillis (int) The number of milliseconds to sleep between runs of the idle connection validation/cleaner thread. This value should not be set under 1 second. It dictates how often we check for idle, abandoned connections, and how often we validate idle connections. The default value is 5000 (5 seconds).