tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fha...@apache.org
Subject svn commit: r708354 - in /tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool: ConnectionPool.java PooledConnection.java
Date Mon, 27 Oct 2008 22:24:26 GMT
Author: fhanik
Date: Mon Oct 27 15:24:26 2008
New Revision: 708354

URL: http://svn.apache.org/viewvc?rev=708354&view=rev
Log:
Improvements to connection handling

Modified:
    tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
    tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java

Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java?rev=708354&r1=708353&r2=708354&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java (original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java Mon
Oct 27 15:24:26 2008
@@ -409,13 +409,15 @@
     protected PooledConnection createConnection(long now, PooledConnection con) {
         //no connections where available we'll create one
         boolean error = false;
+        boolean inbusy = true;
         try {
             //connect and validate the connection
             con = create();
             con.lock();
             if (!busy.offer(con)) {
+                inbusy = false;
                 log.debug("Connection doesn't fit into busy array, connection will not be
traceable.");
-            }
+            } 
             con.connect();
             if (con.validate(PooledConnection.VALIDATE_INIT)) {
                 //no need to lock a new one, its not contented
@@ -424,6 +426,10 @@
                     con.setStackTrace(getThreadDump());
                 }
                 return con;
+            } else {
+                //validation failed, make sure we disconnect
+                //and clean up
+                error =true;
             } //end if
         } catch (Exception e) {
             error = true;
@@ -431,7 +437,7 @@
         } finally {
             if (error ) {
                 release(con);
-                busy.remove(con);
+                if (inbusy) busy.remove(con);
             }
             con.unlock();
         }//catch

Modified: tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java?rev=708354&r1=708353&r2=708354&view=diff
==============================================================================
--- tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
(original)
+++ tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
Mon Oct 27 15:24:26 2008
@@ -61,7 +61,7 @@
     protected void connect() throws SQLException {
         if (connection != null) {
             try {
-                this.disconnect();
+                this.disconnect(false);
             } catch (Exception x) {
                 log.error("Unable to disconnect previous connection.", x);
             } //catch
@@ -90,11 +90,11 @@
     }
 
     protected void reconnect() throws SQLException {
-        this.disconnect();
+        this.disconnect(false);
         this.connect();
     } //reconnect
 
-    protected synchronized void disconnect() throws SQLException {
+    protected synchronized void disconnect(boolean finalize) throws SQLException {
         if (isDiscarded()) {
             return;
         }
@@ -103,7 +103,7 @@
             connection.close();
         }
         connection = null;
-        parent.finalize(this);
+        if (finalize) parent.finalize(this);
     }
 
 
@@ -121,7 +121,7 @@
 
     public boolean abandon() {
         try {
-            disconnect();
+            disconnect(true);
         } catch (SQLException x) {
             log.error("", x);
         } //catch
@@ -157,6 +157,10 @@
     }
 
     public boolean validate(int validateAction,String sql) {
+        if (this.isDiscarded()) {
+            return false;
+        }
+        
         if (!doValidate(validateAction)) {
             //no validation required, no init sql and props not set
             return true;
@@ -202,9 +206,15 @@
      */
     public void release() {
         try {
-            disconnect();
+            disconnect(true);
         } catch (SQLException x) {
-            //TODO
+            if (log.isDebugEnabled()) {
+                log.debug("Unable to close SQL connection",x);
+            }
+        } catch (Exception x) {
+            if (log.isDebugEnabled()) {
+                log.debug("Unable to close SQL connection",x);
+            }
         }
 
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message