2

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:

  1. timeBetweenEvictionRunsMillis, default value is -1
  2. minEvictableIdleTimeMillis, default value is 1800*60*30

I have following two question:

  1. What's the difference between these two parameters?
  2. 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 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

Tom
  • 5,848
  • 12
  • 44
  • 104

1 Answers1

2

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).

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • Thanks @user7294900 for you answer,I updated my question per your comments,could you please take a look? – Tom Aug 09 '17 at 11:52
  • Sorry,I figured out the problem...`timeBetweenEvictionRunsMillis` is the interval to schedule task to validate the objects, and `minEvictableIdleTimeMillis` is the idle time that will be evicted from pool.Since the two parameters are the same, seems that eviction wins – Tom Aug 09 '17 at 11:58
  • Default value of minEvictableIdleTimeMillis is 1000* 60 * 30 – tiwari.vikash Jan 22 '18 at 16:41