From: fhanik Date: Mon, 27 Oct 2008 22:24:26 +0000 (+0000) Subject: Improvements to connection handling X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=5bb3dc3f2e7a6c2ecf0dd32f80efbe1d8824b8c0;p=tomcat7.0 Improvements to connection handling git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@708354 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java index 1b594f32c..f2b94504e 100644 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java @@ -409,13 +409,15 @@ public class ConnectionPool { 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 @@ public class ConnectionPool { 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 @@ public class ConnectionPool { } finally { if (error ) { release(con); - busy.remove(con); + if (inbusy) busy.remove(con); } con.unlock(); }//catch diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java index 79983912a..045aa833c 100644 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java @@ -61,7 +61,7 @@ public class PooledConnection { 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 @@ public class PooledConnection { } 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 @@ public class PooledConnection { connection.close(); } connection = null; - parent.finalize(this); + if (finalize) parent.finalize(this); } @@ -121,7 +121,7 @@ public class PooledConnection { public boolean abandon() { try { - disconnect(); + disconnect(true); } catch (SQLException x) { log.error("", x); } //catch @@ -157,6 +157,10 @@ public class PooledConnection { } 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 class PooledConnection { */ 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); + } } }