Author: fhanik
Date: Sun May 3 00:18:33 2009
New Revision: 771006
URL: http://svn.apache.org/viewvc?rev=771006&view=rev
Log:
Make connection objects non reusable. Once release has been called, it can't be
reused.
This makes the sizing algorithm easier
C3P0 leaks connections during the fairness test, reaches 20 connections even
max is set to 10
Modified:
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java
tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/FairnessTest.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=771006&r1=771005&r2=771006&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
Sun May 3 00:18:33 2009
@@ -60,39 +60,39 @@
/**
* All the information about the connection pool
*/
- protected PoolProperties poolProperties;
+ private PoolProperties poolProperties;
/**
* Contains all the connections that are in use
* TODO - this shouldn't be a blocking queue, simply a list to hold our
objects
*/
- protected BlockingQueue<PooledConnection> busy;
+ private BlockingQueue<PooledConnection> busy;
/**
* Contains all the idle connections
*/
- protected BlockingQueue<PooledConnection> idle;
+ private BlockingQueue<PooledConnection> idle;
/**
* The thread that is responsible for checking abandoned and idle threads
*/
- protected PoolCleaner poolCleaner;
+ private PoolCleaner poolCleaner;
/**
* Pool closed flag
*/
- protected boolean closed = false;
+ private boolean closed = false;
/**
* Since newProxyInstance performs the same operation, over and over
* again, it is much more optimized if we simply store the constructor
ourselves.
*/
- protected Constructor proxyClassConstructor;
+ private Constructor proxyClassConstructor;
/**
* Executor service used to cancel Futures
*/
- protected ThreadPoolExecutor cancellator = new
ThreadPoolExecutor(0,1,1000,TimeUnit.MILLISECONDS,new
LinkedBlockingQueue<Runnable>());
+ private ThreadPoolExecutor cancellator = new
ThreadPoolExecutor(0,1,1000,TimeUnit.MILLISECONDS,new
LinkedBlockingQueue<Runnable>());
/**
* reference to mbean
@@ -102,7 +102,7 @@
/**
* counter to track how many threads are waiting for a connection
*/
- protected AtomicInteger waitcount = new AtomicInteger(0);
+ private AtomicInteger waitcount = new AtomicInteger(0);
//===============================================================================
// PUBLIC METHODS
@@ -427,9 +427,11 @@
return;
try {
con.lock();
- con.release();
+ if (con.release()) {
+ size.addAndGet(-1);
+ }
} finally {
- size.addAndGet(-1);
+
con.unlock();
}
}
@@ -441,7 +443,7 @@
* @return PooledConnection
* @throws SQLException
*/
- protected PooledConnection borrowConnection(int wait) throws SQLException {
+ private PooledConnection borrowConnection(int wait) throws SQLException {
if (isClosed()) {
throw new SQLException("Connection pool closed.");
Modified:
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java?rev=771006&r1=771005&r2=771006&view=diff
==============================================================================
---
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
(original)
+++
tomcat/trunk/modules/jdbc-pool/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
Sun May 3 00:18:33 2009
@@ -26,6 +26,7 @@
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
/**
@@ -109,6 +110,8 @@
*/
private WeakReference<JdbcInterceptor> handler = null;
+ private AtomicBoolean released = new AtomicBoolean(false);
+
public PooledConnection(PoolProperties prop, ConnectionPool parent) {
instanceCount = counter.addAndGet(1);
@@ -117,6 +120,7 @@
}
public void connect() throws SQLException {
+ if (released.get()) throw new SQLException("A connection once
released, can't be reestablished.");
if (connection != null) {
try {
this.disconnect(false);
@@ -292,7 +296,7 @@
/**
* This method is called if (Now - timeCheckedIn > getReleaseTime())
*/
- public void release() {
+ public boolean release() {
try {
disconnect(true);
} catch (Exception x) {
@@ -300,6 +304,7 @@
log.debug("Unable to close SQL connection",x);
}
}
+ return released.compareAndSet(false, true);
}
Modified:
tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java?rev=771006&r1=771005&r2=771006&view=diff
==============================================================================
---
tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java
(original)
+++
tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/DefaultTestCase.java
Sun May 3 00:18:33 2009
@@ -39,7 +39,7 @@
public class DefaultTestCase extends TestCase {
protected org.apache.tomcat.jdbc.pool.DataSource datasource;
protected BasicDataSource tDatasource;
- protected DataSource c3p0Datasource;
+ protected ComboPooledDataSource c3p0Datasource;
protected int threadcount = 10;
protected int iterations = 100000;
public DefaultTestCase(String name) {
Modified:
tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/FairnessTest.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/FairnessTest.java?rev=771006&r1=771005&r2=771006&view=diff
==============================================================================
---
tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/FairnessTest.java
(original)
+++
tomcat/trunk/modules/jdbc-pool/test/org/apache/tomcat/jdbc/test/FairnessTest.java
Sun May 3 00:18:33 2009
@@ -41,7 +41,7 @@
protected long complete = Long.getLong("complete",20000);
protected boolean printthread = Boolean.getBoolean("printthread");
CountDownLatch latch = null;
- protected void printThreadResults(TestThread[] threads, String name) {
+ protected void printThreadResults(TestThread[] threads, String name, int
active, int expected) {
long minfetch = Long.MAX_VALUE, maxfetch = Long.MIN_VALUE, totalfetch
= 0;
long maxwait = 0, minwait = Long.MAX_VALUE, averagewait = 0, totalwait
= 0;
float avgfetch = 0;
@@ -59,6 +59,7 @@
System.out.println("["+name+"] Max fetch:"+(maxfetch)+" Min
fetch:"+(minfetch)+" Average fetch:"+
(((float)totalfetch))/(float)threads.length);
System.out.println("["+name+"] Max
wait:"+(((float)maxwait)/1000000f)+"ms. Min
wait:"+(((float)minwait)/1000000f)+"ms. Average
wait:"+(((((float)totalwait))/(float)totalfetch)/1000000f)+" ms.");
+ System.out.println("["+name+"] Max active:"+active+" Expected
Active:"+expected);
}
@@ -87,7 +88,7 @@
}
this.run = false;
long delta = System.currentTimeMillis() - start;
- printThreadResults(threads,"testDBCPThreads20Connections10");
+
printThreadResults(threads,"testDBCPThreads20Connections10",this.tDatasource.getNumActive(),10);
tearDown();
}
@@ -116,7 +117,7 @@
}
this.run = false;
long delta = System.currentTimeMillis() - start;
- printThreadResults(threads,"testPoolThreads20Connections10");
+
printThreadResults(threads,"testPoolThreads20Connections10",this.datasource.getSize(),10);
tearDown();
}
@@ -146,7 +147,7 @@
}
this.run = false;
long delta = System.currentTimeMillis() - start;
- printThreadResults(threads,"testPoolThreads20Connections10Fair");
+
printThreadResults(threads,"testPoolThreads20Connections10Fair",this.datasource.getSize(),10);
tearDown();
}
@@ -176,7 +177,7 @@
}
this.run = false;
long delta = System.currentTimeMillis() - start;
- printThreadResults(threads,"testPoolThreads20Connections10FairAsync");
+
printThreadResults(threads,"testPoolThreads20Connections10FairAsync",this.datasource.getSize(),10);
tearDown();
}
@@ -205,7 +206,7 @@
}
this.run = false;
long delta = System.currentTimeMillis() - start;
- printThreadResults(threads,"testC3P0Threads20Connections10");
+
printThreadResults(threads,"testC3P0Threads20Connections10",c3p0Datasource.getNumConnectionsAllUsers(),10);
tearDown();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]