pool.setMaxIdle(-1);
pool.setTimeBetweenEvictionRunsMillis(1000 * 60 * 5);
pool.setMinEvictableIdleTimeMillis(1000 * 60 * 5);
try {
ManagedGenericKeyedObjectPool mbean =
new ManagedGenericKeyedObjectPool(
pool,
poolName);
ManagementFactory.getPlatformMBeanServer()
.registerMBean(mbean, mbean.getObjectName());
} catch (Exception e) {
log.error("Could not register mbean for pool [{}]", poolName, e);
}
return pool;