Fix fair blocking queue for now, we will add back the ability to not have a timeout...
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 24 Nov 2008 22:04:23 +0000 (22:04 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 24 Nov 2008 22:04:23 +0000 (22:04 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@720306 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/test/org/apache/tomcat/jdbc/test/FairnessTest.java

index bcb6cc5..91c4d91 100644 (file)
@@ -424,8 +424,8 @@ public class ConnectionPool {
             //we didn't get a connection, lets see if we timed out
             if (con == null) {
                 if ((System.currentTimeMillis() - now) >= maxWait) {
-                    throw new SQLException(
-                        "Pool empty. Unable to fetch a connection in " + (maxWait / 1000) +
+                    throw new SQLException("[" + Thread.currentThread().getName()+"] " +
+                        "Timeout: Pool empty. Unable to fetch a connection in " + (maxWait / 1000) +
                         " seconds, none available["+busy.size()+" in use].");
                 } else {
                     //no timeout, lets try again
index 4eea64b..c25e207 100644 (file)
@@ -76,7 +76,7 @@ public class FairBlockingQueue<E> implements BlockingQueue<E> {
         lock.lock();
         try {
             result = items.poll();
-            if (result==null && timeout>0) {
+            if (result==null) {
                 ExchangeCountDownLatch<E> c = new ExchangeCountDownLatch<E>(1);
                 waiters.addLast(c);
                 lock.unlock();
index c2dc742..69cefcc 100644 (file)
@@ -55,6 +55,7 @@ public class FairnessTest extends DefaultTestCase {
     }
     
     public void testDBCPThreads20Connections10() throws Exception {
+        System.out.println("Starting fairness - DBCP");
         init();
         this.datasource.getPoolProperties().setMaxActive(10);
         this.threadcount = 20;
@@ -76,10 +77,12 @@ public class FairnessTest extends DefaultTestCase {
         this.run = false;
         long delta = System.currentTimeMillis() - start;
         printThreadResults(threads,"testDBCPThreads20Connections10");
+        System.out.println("Completed fairness - DBCP");
         tearDown();
     }
 
     public void testPoolThreads20Connections10() throws Exception {
+        System.out.println("Starting fairness - Tomcat JDBC - Non Fair");
         init();
         this.datasource.getPoolProperties().setMaxActive(10);
         this.threadcount = 20;
@@ -101,11 +104,13 @@ public class FairnessTest extends DefaultTestCase {
         this.run = false;
         long delta = System.currentTimeMillis() - start;
         printThreadResults(threads,"testPoolThreads20Connections10");
+        System.out.println("Completed fairness - Tomcat JDBC - Non Fair");
         tearDown();
 
     }
 
     public void testPoolThreads20Connections10Fair() throws Exception {
+        System.out.println("Starting fairness - Tomcat JDBC - Fair");
         init();
         this.datasource.getPoolProperties().setMaxActive(10);
         this.datasource.getPoolProperties().setFairQueue(true);
@@ -128,6 +133,7 @@ public class FairnessTest extends DefaultTestCase {
         this.run = false;
         long delta = System.currentTimeMillis() - start;
         printThreadResults(threads,"testPoolThreads20Connections10Fair");
+        System.out.println("Completed fairness - Tomcat JDBC - Fair");
         tearDown();
     }