in src/main/java/org/apache/commons/pool3/impl/GenericKeyedObjectPool.java [882:914]
private boolean destroy(final K key, final PooledObject<T> toDestroy, final boolean always, final DestroyMode destroyMode) throws E {
final ObjectDeque<T> objectDeque = register(key);
try {
boolean isIdle;
synchronized (toDestroy) {
// Check idle state directly
isIdle = toDestroy.getState().equals(PooledObjectState.IDLE);
// If idle, not under eviction test, or always is true, remove instance,
// updating isIdle if instance is found in idle objects
if (isIdle || always) {
isIdle = objectDeque.getIdleObjects().remove(toDestroy);
}
}
if (isIdle || always) {
objectDeque.getAllObjects().remove(IdentityWrapper.on(toDestroy));
toDestroy.invalidate();
try {
factory.destroyObject(key, toDestroy, destroyMode);
} finally {
objectDeque.getCreateCount().decrementAndGet();
destroyedCount.incrementAndGet();
numTotal.decrementAndGet();
}
return true;
}
return false;
} finally {
deregister(key);
}
}