Author: fhanik
Date: Tue Oct 28 07:34:28 2008
New Revision: 708586
URL: http://svn.apache.org/viewvc?rev=708586&view=rev
Log:
Improve validation ordering, when a connection has been acquired, but
validation failed, don't let the thread go back into polling mode, instead try
to reconnect it.
Modified:
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.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=708586&r1=708585&r2=708586&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
Tue Oct 28 07:34:28 2008
@@ -330,7 +330,7 @@
try {
con.lock();
if (getPoolProperties().isLogAbandoned()) {
- log.warn("Connection has been abandoned" + con + ":"
+con.getStackTrace());
+ log.warn("Connection has been abandoned " + con + ":"
+con.getStackTrace());
}
con.abandon();
} finally {
@@ -409,15 +409,10 @@
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
@@ -425,6 +420,9 @@
if (getPoolProperties().isLogAbandoned()) {
con.setStackTrace(getThreadDump());
}
+ if (!busy.offer(con)) {
+ log.debug("Connection doesn't fit into busy array,
connection will not be traceable.");
+ }
return con;
} else {
//validation failed, make sure we disconnect
@@ -437,7 +435,6 @@
} finally {
if (error ) {
release(con);
- if (inbusy) busy.remove(con);
}
con.unlock();
}//catch
@@ -449,10 +446,7 @@
boolean setToNull = false;
try {
con.lock();
- if (con.isDiscarded()) {
- //connection has already been disconnected
- setToNull = true;
- } else if (con.validate(PooledConnection.VALIDATE_BORROW)) {
+ if ((!con.isDiscarded()) &&
con.validate(PooledConnection.VALIDATE_BORROW)) {
//set the timestamp
con.setTimestamp(now);
if (getPoolProperties().isLogAbandoned()) {
@@ -463,11 +457,33 @@
log.debug("Connection doesn't fit into busy array,
connection will not be traceable.");
}
return con;
- } else {
- /*if the object wasn't validated, we may as well remove it*/
- release(con);
+ }
+ //if we reached here, that means the connection
+ //is either discarded or validation failed.
+ //we will make one more attempt
+ //in order to guarantee that the thread that just acquired
+ //the connection shouldn't have to poll again.
+ try {
+ con.reconnect();
+ if (con.validate(PooledConnection.VALIDATE_INIT)) {
+ //set the timestamp
+ con.setTimestamp(now);
+ if (getPoolProperties().isLogAbandoned()) {
+ //set the stack trace for this pool
+ con.setStackTrace(getThreadDump());
+ }
+ if (!busy.offer(con)) {
+ log.debug("Connection doesn't fit into busy array,
connection will not be traceable.");
+ }
+ return con;
+ } else {
+ release(con);
+ setToNull = true;
+ }
+ } catch (Exception x) {
+ release(con);
setToNull = true;
- } //end if
+ }
} finally {
con.unlock();
if (setToNull) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]