From 8955b0f8df05099c339d6c801354248c679445c0 Mon Sep 17 00:00:00 2001 From: fhanik Date: Mon, 24 Nov 2008 22:04:23 +0000 Subject: [PATCH] Fix fair blocking queue for now, we will add back the ability to not have a timeout later git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@720306 13f79535-47bb-0310-9956-ffa450edef68 --- .../jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java | 4 ++-- .../java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java | 2 +- .../jdbc-pool/test/org/apache/tomcat/jdbc/test/FairnessTest.java | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java index bcb6cc50f..91c4d9141 100644 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java @@ -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 diff --git a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java index 4eea64be8..c25e20716 100644 --- a/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java +++ b/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/FairBlockingQueue.java @@ -76,7 +76,7 @@ public class FairBlockingQueue implements BlockingQueue { lock.lock(); try { result = items.poll(); - if (result==null && timeout>0) { + if (result==null) { ExchangeCountDownLatch c = new ExchangeCountDownLatch(1); waiters.addLast(c); lock.unlock(); diff --git a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/FairnessTest.java b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/FairnessTest.java index c2dc742da..69cefccbd 100644 --- a/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/FairnessTest.java +++ b/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/FairnessTest.java @@ -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(); } -- 2.11.0