You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2007/10/06 18:19:51 UTC

svn commit: r582513 - /jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java

Author: sebb
Date: Sat Oct  6 09:19:50 2007
New Revision: 582513

URL: http://svn.apache.org/viewvc?rev=582513&view=rev
Log:
Allow multiple per-thread pools

Modified:
    jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java

Modified: jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java?rev=582513&r1=582512&r2=582513&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java (original)
+++ jakarta/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/config/DataSourceElement.java Sat Oct  6 09:19:50 2007
@@ -19,8 +19,10 @@
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.avalon.excalibur.datasource.DataSourceComponent;
@@ -68,11 +70,6 @@
 	public DataSourceElement() {
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.jmeter.testelement.TestListener#testEnded()
-	 */
 	public void testEnded() {
 		synchronized (this) {
 			if (excaliburSource != null) {
@@ -90,28 +87,13 @@
 		}
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.jmeter.testelement.TestListener#testEnded(java.lang.String)
-	 */
 	public void testEnded(String host) {
 		testEnded();
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.jmeter.testelement.TestListener#testIterationStart(org.apache.jmeter.engine.event.LoopIterationEvent)
-	 */
 	public void testIterationStart(LoopIterationEvent event) {
 	}
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.jmeter.testelement.TestListener#testStarted()
-	 */
 	public void testStarted() {
         this.setRunningVersion(true);
         TestBeanHelper.prepare(this);
@@ -133,6 +115,16 @@
 		}
 	}
 
+	public void testStarted(String host) {
+		testStarted();
+	}
+
+	public Object clone() {
+		DataSourceElement el = (DataSourceElement) super.clone();
+		el.excaliburSource = excaliburSource;
+		return el;
+	}
+
 	/*
 	 * Utility routine to get the connection from the pool.
 	 * Purpose:
@@ -147,26 +139,11 @@
 		}
 		return pool.getConnection();
 	}
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.jmeter.testelement.TestListener#testStarted(java.lang.String)
-	 */
-	public void testStarted(String host) {
-		testStarted();
-	}
 
 	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see java.lang.Object#clone()
-	 */
-	public Object clone() {
-		DataSourceElement el = (DataSourceElement) super.clone();
-		el.excaliburSource = excaliburSource;
-		return el;
-	}
-
+	 * Set up the DataSource - maxPool is a parameter, so the same code can
+	 * also be used for setting up the per-thread pools.
+	*/
 	private ResourceLimitingJdbcDataSource initPool(String maxPool) {
 		ResourceLimitingJdbcDataSource source = null;
 		source = new ResourceLimitingJdbcDataSource();
@@ -251,7 +228,11 @@
 	}
 
 	// used to hold per-thread singleton connection pools
-	private static ThreadLocal perThreadPool = new ThreadLocal();
+	private static ThreadLocal perThreadPoolMap = new ThreadLocal(){
+		protected synchronized Object initialValue() {
+            return new HashMap();
+        }
+	};
 	
 	/*
 	 * Wrapper class to allow getConnection() to be implemented for both shared
@@ -276,10 +257,11 @@
 			if (sharedDSC != null){ // i.e. shared pool
 				dsc = sharedDSC;
 			} else {
-				dsc = (DataSourceComponent) perThreadPool.get();
+				Map poolMap = (Map) perThreadPoolMap.get();
+				dsc = (DataSourceComponent) poolMap.get(getDataSource());
 				if (dsc == null){
 					dsc = initPool("1");
-					perThreadPool.set(dsc);
+					poolMap.put(getDataSource(),dsc);
 					perThreadPoolSet.add(dsc);
 				}
 			}



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org