dirkv 2003/08/26 09:38:57
Modified: pool/src/java/org/apache/commons/pool/impl
GenericObjectPool.java
Log:
unsynchronize the addObject loop (minIdle)
Revision Changes Path
1.28 +30 -11
jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericObjectPool.java
Index: GenericObjectPool.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/pool/src/java/org/apache/commons/pool/impl/GenericObjectPool.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- GenericObjectPool.java 22 Aug 2003 14:33:30 -0000 1.27
+++ GenericObjectPool.java 26 Aug 2003 16:38:57 -0000 1.28
@@ -1000,18 +1000,32 @@
}
}
} // if !empty
-
- // Check to see if we are below our minimum number of objects
- // if so enough to bring us back to our minimum.
+ }
+
+ /**
+ * Check to see if we are below our minimum number of objects
+ * if so enough to bring us back to our minimum.
+ */
+ private void ensureMinIdle() throws Exception {
+ // this method isn't synchronized so the
+ // calculateDeficit is done at the beginning
+ // as a loop limit and a second time inside the loop
+ // to stop when another thread already returned the
+ // needed objects
+ int objectDeficit = calculateDeficit();
+ for ( int j = 0 ; j < objectDeficit && calculateDeficit() > 0 ; j++ ) {
+ addObject();
+ }
+ }
+
+ private synchronized int calculateDeficit() {
int objectDeficit = getMinIdle() - getNumIdle();
if (_maxActive > 0) {
int growLimit = Math.max(0, getMaxActive() - getNumActive() -
getNumIdle());
objectDeficit = Math.min(objectDeficit, growLimit);
}
- for ( int j = 0; j < objectDeficit; j++ ) {
- addObject();
- }
- }
+ return objectDeficit;
+ }
/**
* Create an object, and place it into the pool.
@@ -1111,6 +1125,11 @@
}
try {
evict();
+ } catch(Exception e) {
+ // ignored
+ }
+ try {
+ ensureMinIdle();
} catch(Exception e) {
// ignored
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]