Author: markt
Date: Mon Mar  3 10:21:23 2014
New Revision: 1573510

URL: http://svn.apache.org/r1573510
Log:
Small performance tweak. The improvement is just about visible.

Modified:
    commons/proper/dbcp/trunk/src/changes/changes.xml
    
commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java

Modified: commons/proper/dbcp/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/changes/changes.xml?rev=1573510&r1=1573509&r2=1573510&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/changes/changes.xml (original)
+++ commons/proper/dbcp/trunk/src/changes/changes.xml Mon Mar  3 10:21:23 2014
@@ -60,6 +60,11 @@ The <action> type attribute can be add,u
      -->
 
   <body>
+    <release version="2.0.1" date="TBD" description="This is a bug fix 
release">
+      <action dev="markt" type="fix">
+        Small performance improvement when returning connections to the pool.
+      </action>
+    </release>
     <release version="2.0" date="3 March 2014" description=
 "This release includes new features as well as bug fixes and enhancements.
  Version 2.0.x supports JDBC 4.1, so requires Java 7.

Modified: 
commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java
URL: 
http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java?rev=1573510&r1=1573509&r2=1573510&view=diff
==============================================================================
--- 
commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java
 (original)
+++ 
commons/proper/dbcp/trunk/src/main/java/org/apache/commons/dbcp2/PoolableConnection.java
 Mon Mar  3 10:21:23 2014
@@ -139,12 +139,24 @@ public class PoolableConnection extends 
         }
 
         /* Can't set close before this code block since the connection needs to
-         * be open when validation runs. Can't set close after this code black
+         * be open when validation runs. Can't set close after this code block
          * since by then the connection will have been returned to the pool and
          * may have been borrowed by another thread. Therefore, the close flag
          * is set in passivate().
          */
-        if (!isUnderlyingConectionClosed) {
+        if (isUnderlyingConectionClosed) {
+            // Abnormal close: underlying connection closed unexpectedly, so we
+            // must destroy this proxy
+            try {
+                _pool.invalidateObject(this);
+            } catch(IllegalStateException e) {
+                // pool is closed, so close the connection
+                passivate();
+                getInnermostDelegate().close();
+            } catch (Exception e) {
+                throw new SQLException("Cannot close connection (invalidating 
pooled object failed)", e);
+            }
+        } else {
             // Normal close: underlying connection is still open, so we
             // simply need to return this proxy to the pool
             try {
@@ -160,18 +172,6 @@ public class PoolableConnection extends 
             } catch(Exception e) {
                 throw new SQLException("Cannot close connection (return to 
pool failed)", e);
             }
-        } else {
-            // Abnormal close: underlying connection closed unexpectedly, so we
-            // must destroy this proxy
-            try {
-                _pool.invalidateObject(this);
-            } catch(IllegalStateException e) {
-                // pool is closed, so close the connection
-                passivate();
-                getInnermostDelegate().close();
-            } catch (Exception e) {
-                throw new SQLException("Cannot close connection (invalidating 
pooled object failed)", e);
-            }
         }
     }
 


Reply via email to