Reputation: 424
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?
Upvotes: 1
Views: 1609
Reputation: 382
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.
Upvotes: 0