1

I have this pool of objects (using org.apache.commons.pool2), from which I borrow (or create) one.

The maximum idle size I have set is 3 ( with a max size of 5). This was set with the understanding that if there are idle objects more than 3, those would be destroyed (BasePooledObjectFactory#destroyObject)

What this does in my system is that it creates and destroys several objects, which is expensive. I would only want it to be destroyed when idle for a longer period (say 1 minute).

I tried setting setMinEvictableIdleTimeMillis (the default is 30 minutes I could see) to do this. The default, as well as the setting doesn't seem to work - as in I can see that the object is being destroyed quite often as the idle count goes above 4.

Why could this be happening and how can I make sure the idle objects are not destroyed this often?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
user1583803
  • 424
  • 2
  • 6
  • 16
  • Not verified, so just as a comment: I think what you want is minIdle = 3, maxIdle = maxTotal = 5. => Keep at least 3 idle objects indefinitely, up to 5 if idle for less than minEvictableIdleTime. – EndlosSchleife Apr 26 '21 at 17:50

1 Answers1

0

using minEvictableIdleTimeMillis only is not enough

you must also specify timeBetweenEvictionRunsMillis which is -1 by default.

pool objects are being evicted by a validation/cleaner thread, so timeBetweenEvictionRunsMillis will make this thread run, so it will check the minEvictableIdleTimeMillis of the ideal threads and will evict them.

Mohammed Nosirat
  • 324
  • 1
  • 3
  • 15