try {\r
con.lock();\r
if (getPoolProperties().isLogAbandoned()) {\r
- log.warn("Connection has been abandoned" + con + ":" +con.getStackTrace());\r
+ log.warn("Connection has been abandoned " + con + ":" +con.getStackTrace());\r
}\r
con.abandon();\r
} finally {\r
protected PooledConnection createConnection(long now, PooledConnection con) {\r
//no connections where available we'll create one\r
boolean error = false;\r
- boolean inbusy = true;\r
try {\r
//connect and validate the connection\r
con = create();\r
con.lock();\r
- if (!busy.offer(con)) {\r
- inbusy = false;\r
- log.debug("Connection doesn't fit into busy array, connection will not be traceable.");\r
- } \r
con.connect();\r
if (con.validate(PooledConnection.VALIDATE_INIT)) {\r
//no need to lock a new one, its not contented\r
if (getPoolProperties().isLogAbandoned()) {\r
con.setStackTrace(getThreadDump());\r
}\r
+ if (!busy.offer(con)) {\r
+ log.debug("Connection doesn't fit into busy array, connection will not be traceable.");\r
+ }\r
return con;\r
} else {\r
//validation failed, make sure we disconnect\r
} finally {\r
if (error ) {\r
release(con);\r
- if (inbusy) busy.remove(con);\r
}\r
con.unlock();\r
}//catch\r
boolean setToNull = false;\r
try {\r
con.lock();\r
- if (con.isDiscarded()) {\r
- //connection has already been disconnected\r
- setToNull = true;\r
- } else if (con.validate(PooledConnection.VALIDATE_BORROW)) {\r
+ if ((!con.isDiscarded()) && con.validate(PooledConnection.VALIDATE_BORROW)) {\r
//set the timestamp\r
con.setTimestamp(now);\r
if (getPoolProperties().isLogAbandoned()) {\r
log.debug("Connection doesn't fit into busy array, connection will not be traceable.");\r
}\r
return con;\r
- } else {\r
- /*if the object wasn't validated, we may as well remove it*/\r
- release(con);\r
+ }\r
+ //if we reached here, that means the connection\r
+ //is either discarded or validation failed.\r
+ //we will make one more attempt\r
+ //in order to guarantee that the thread that just acquired\r
+ //the connection shouldn't have to poll again.\r
+ try {\r
+ con.reconnect();\r
+ if (con.validate(PooledConnection.VALIDATE_INIT)) {\r
+ //set the timestamp\r
+ con.setTimestamp(now);\r
+ if (getPoolProperties().isLogAbandoned()) {\r
+ //set the stack trace for this pool\r
+ con.setStackTrace(getThreadDump());\r
+ }\r
+ if (!busy.offer(con)) {\r
+ log.debug("Connection doesn't fit into busy array, connection will not be traceable.");\r
+ }\r
+ return con;\r
+ } else {\r
+ release(con);\r
+ setToNull = true;\r
+ }\r
+ } catch (Exception x) {\r
+ release(con); \r
setToNull = true;\r
- } //end if\r
+ }\r
} finally {\r
con.unlock();\r
if (setToNull) {\r