When using the fair queue, use a much more efficient idle connection handling by...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 15 Apr 2009 05:44:43 +0000 (05:44 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 15 Apr 2009 05:44:43 +0000 (05:44 +0000)
so that connections are reused properly

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@765054 13f79535-47bb-0310-9956-ffa450edef68

modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java

index dbb7471..2cea90d 100644 (file)
@@ -630,7 +630,7 @@ public class ConnectionPool {
                             con.validate(PooledConnection.VALIDATE_RETURN)) {
                         con.setStackTrace(null);
                         con.setTimestamp(System.currentTimeMillis());
-                        if ((idle.size()>=poolProperties.getMaxIdle()) || (!idle.offer(con))) {
+                        if (((idle.size()>=poolProperties.getMaxIdle()) && !poolProperties.isPoolSweeperEnabled()) || (!idle.offer(con))) {
                             if (log.isDebugEnabled()) {
                                 log.debug("Connection ["+con+"] will be closed and not returned to the pool, idle["+idle.size()+"]>=maxIdle["+poolProperties.getMaxIdle()+"] idle.offer failed.");
                             }
@@ -920,7 +920,7 @@ public class ConnectionPool {
                     try {
                         if (pool.getPoolProperties().isRemoveAbandoned())
                             pool.checkAbandoned();
-                        if (pool.getPoolProperties().getMaxIdle()<pool.idle.size())
+                        if (pool.getPoolProperties().getMinIdle()<pool.idle.size())
                             pool.checkIdle();
                         if (pool.getPoolProperties().isTestWhileIdle())
                             pool.testAllIdle();
index 636bddc..67f83e5 100644 (file)
@@ -63,7 +63,7 @@ public class FairBlockingQueue<E> implements BlockingQueue<E> {
                 c = waiters.poll();
                 c.setItem(e);
             } else {
-                items.add(e);
+                items.addFirst(e);
             }
         } finally {
             lock.unlock();
index 4e46675..c16f7a8 100644 (file)
@@ -45,7 +45,7 @@ public class PoolProperties {
     protected String connectionProperties;
     protected int initialSize = 10;
     protected int maxActive = 100;
-    protected int maxIdle = maxActive;
+    protected int maxIdle = Integer.MAX_VALUE;
     protected int minIdle = initialSize;
     protected int maxWait = 30000;
     protected String validationQuery;
index 32e34c4..a658d98 100644 (file)
@@ -154,7 +154,7 @@ public class ConnectionPool extends NotificationBroadcasterSupport implements Co
     }
     
     public int getNumActive() {
-        return getNumActive();
+        return getActive();
     }
 
     //=================================================================