Skip to content

Commit 8f46cde

Browse files
committed
Remove sync lock in addObject.
1 parent c406b01 commit 8f46cde

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

src/main/java/org/apache/commons/pool2/impl/GenericObjectPool.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,11 @@ public void addObject() throws Exception {
212212
if (factory == null) {
213213
throw new IllegalStateException("Cannot add objects without a factory.");
214214
}
215-
synchronized (makeObjectCountLock) {
216-
final int localMaxTotal = getMaxTotal();
217-
final int localMaxIdle = getMaxIdle();
218-
if (localMaxIdle >= 0 && getNumIdle() >= localMaxIdle) {
219-
// Pool already has maxIdle idle objects or maxIdle is 0.
220-
return;
221-
}
222-
if (localMaxTotal < 0 || createCount.get() < localMaxTotal) {
223-
addIdleObject(create(getMaxWaitDuration()));
224-
}
215+
final int localMaxIdle = getMaxIdle();
216+
final int localMaxTotal = getMaxTotal();
217+
if ((localMaxIdle < 0 || getNumIdle() < localMaxIdle) &&
218+
(localMaxTotal < 0 || createCount.get() < localMaxTotal)) {
219+
addIdleObject(create(getMaxWaitDuration()));
225220
}
226221
}
227222

0 commit comments

Comments
 (0)