commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r787048 - in /commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources: PerUserPoolDataSource.java SharedPoolDataSource.java
Date Sun, 21 Jun 2009 16:27:18 GMT
Author: markt
Date: Sun Jun 21 16:27:18 2009
New Revision: 787048

URL: http://svn.apache.org/viewvc?rev=787048&view=rev
Log:
Fix DBCP-291. Narrow sync so we don't call borrowObject() inside the sync. If pool is exhausted
and N threads request objects the requests will time out at maxWait, 2*maxWait, 3*maxWait,
..., n*maxWait rather than all timing out at maxWait.

Modified:
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java?rev=787048&r1=787047&r2=787048&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java
(original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/PerUserPoolDataSource.java
Sun Jun 21 16:27:18 2009
@@ -356,18 +356,20 @@
     // ----------------------------------------------------------------------
     // Inherited abstract methods
 
-    protected synchronized PooledConnectionAndInfo 
+    protected PooledConnectionAndInfo 
         getPooledConnectionAndInfo(String username, String password)
         throws SQLException {
 
         PoolKey key = getPoolKey(username);
         Object pool = pools.get(key);
-        if (pool == null) {
-            try {
-                registerPool(username, password);
-                pool = pools.get(key);
-            } catch (NamingException e) {
-                throw new SQLNestedException("RegisterPool failed", e);
+        synchronized(this) {
+            if (pool == null) {
+                try {
+                    registerPool(username, password);
+                    pool = pools.get(key);
+                } catch (NamingException e) {
+                    throw new SQLNestedException("RegisterPool failed", e);
+                }
             }
         }
 

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java?rev=787048&r1=787047&r2=787048&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java
(original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/datasources/SharedPoolDataSource.java
Sun Jun 21 16:27:18 2009
@@ -151,14 +151,17 @@
     // ----------------------------------------------------------------------
     // Inherited abstract methods
 
-    protected synchronized PooledConnectionAndInfo 
+    protected PooledConnectionAndInfo 
         getPooledConnectionAndInfo(String username, String password)
         throws SQLException {
-        if (pool == null) {
-            try {
-                registerPool(username, password);
-            } catch (NamingException e) {
-                throw new SQLNestedException("RegisterPool failed", e);
+        
+        synchronized(this) {
+            if (pool == null) {
+                try {
+                    registerPool(username, password);
+                } catch (NamingException e) {
+                    throw new SQLNestedException("RegisterPool failed", e);
+                }
             }
         }
 



Mime
View raw message