You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by fh...@apache.org on 2008/11/23 00:13:05 UTC
svn commit: r719936 -
/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
Author: fhanik
Date: Sat Nov 22 15:13:05 2008
New Revision: 719936
URL: http://svn.apache.org/viewvc?rev=719936&view=rev
Log:
Add ability to customize wait plan
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=719936&r1=719935&r2=719936&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 Sat Nov 22 15:13:05 2008
@@ -123,7 +123,7 @@
*/
public Connection getConnection() throws SQLException {
//check out a connection
- PooledConnection con = (PooledConnection)borrowConnection();
+ PooledConnection con = (PooledConnection)borrowConnection(-1);
return setupConnection(con);
}
@@ -316,7 +316,7 @@
PooledConnection[] initialPool = new PooledConnection[poolProperties.getInitialSize()];
try {
for (int i = 0; i < initialPool.length; i++) {
- initialPool[i] = this.borrowConnection();
+ initialPool[i] = this.borrowConnection(0); //don't wait, should be no contention
} //for
} catch (SQLException x) {
@@ -376,10 +376,12 @@
/**
* Thread safe way to retrieve a connection from the pool
+ * @param wait - time to wait, overrides the maxWait from the properties,
+ * set to -1 if you wish to use maxWait, 0 if you wish no wait time.
* @return PooledConnection
* @throws SQLException
*/
- protected PooledConnection borrowConnection() throws SQLException {
+ protected PooledConnection borrowConnection(int wait) throws SQLException {
if (isClosed()) {
throw new SQLException("Connection pool closed.");
@@ -405,7 +407,10 @@
} //end if
//calculate wait time for this iteration
- long maxWait = (getPoolProperties().getMaxWait()<=0)?Long.MAX_VALUE:getPoolProperties().getMaxWait();
+ long maxWait = wait;
+ if (wait==-1) {
+ maxWait = (getPoolProperties().getMaxWait()<=0)?Long.MAX_VALUE:getPoolProperties().getMaxWait();
+ }
long timetowait = Math.max(0, maxWait - (System.currentTimeMillis() - now));
try {
//retrieve an existing connection
@@ -413,6 +418,9 @@
} catch (InterruptedException ex) {
Thread.currentThread().interrupted();
}
+ if (maxWait==0) { //no wait, return one if we have one
+ return con;
+ }
//we didn't get a connection, lets see if we timed out
if (con == null) {
if ((System.currentTimeMillis() - now) >= maxWait) {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org