jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1224967 - in /jmeter/trunk: src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java xdocs/changes.xml
Date Tue, 27 Dec 2011 18:22:31 GMT
Author: pmouawad
Date: Tue Dec 27 18:22:31 2011
New Revision: 1224967

URL: http://svn.apache.org/viewvc?rev=1224967&view=rev
Log:
Bug 52390 - AbstractJDBCTestElement:Memory leak and synchronization issue in perConnCache

Modified:
    jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java?rev=1224967&r1=1224966&r2=1224967&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java
(original)
+++ jmeter/trunk/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java
Tue Dec 27 18:22:31 2011
@@ -31,6 +31,7 @@ import java.sql.Statement;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -38,9 +39,11 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.jmeter.engine.event.LoopIterationEvent;
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.save.CSVSaveService;
 import org.apache.jmeter.testelement.AbstractTestElement;
+import org.apache.jmeter.testelement.TestListener;
 import org.apache.jmeter.threads.JMeterVariables;
 import org.apache.jmeter.util.JMeterUtils;
 import org.apache.jorphan.logging.LoggingManager;
@@ -50,7 +53,7 @@ import org.apache.log.Logger;
  * A base class for all JDBC test elements handling the basics of a SQL request.
  * 
  */
-public abstract class AbstractJDBCTestElement extends AbstractTestElement {
+public abstract class AbstractJDBCTestElement extends AbstractTestElement implements TestListener{
     private static final long serialVersionUID = 235L;
 
     private static final Logger log = LoggingManager.getLoggerForClass();
@@ -127,7 +130,7 @@ public abstract class AbstractJDBCTestEl
      *  from the least recently used connections.
      */
     private static final Map<Connection, Map<String, PreparedStatement>> perConnCache
=
-        new LinkedHashMap<Connection, Map<String, PreparedStatement>>(MAX_ENTRIES){
+        Collections.synchronizedMap(new LinkedHashMap<Connection, Map<String, PreparedStatement>>(MAX_ENTRIES){
         private static final long serialVersionUID = 1L;
         @Override
         protected boolean removeEldestEntry(Map.Entry<Connection, Map<String, PreparedStatement>>
arg0) {
@@ -138,7 +141,7 @@ public abstract class AbstractJDBCTestEl
             }
             return false;
         }
-    };
+    });
 
     /**
      * Creates a JDBCSampler.
@@ -322,7 +325,7 @@ public abstract class AbstractJDBCTestEl
         Map<String, PreparedStatement> preparedStatementMap = perConnCache.get(conn);
         if (null == preparedStatementMap ) {
             // MRU PreparedStatements cache.
-            preparedStatementMap = new LinkedHashMap<String, PreparedStatement>(MAX_ENTRIES)
{
+            preparedStatementMap = Collections.synchronizedMap(new LinkedHashMap<String,
PreparedStatement>(MAX_ENTRIES) {
                 private static final long serialVersionUID = 240L;
 
                 @Override
@@ -338,7 +341,7 @@ public abstract class AbstractJDBCTestEl
                     }
                     return false;
                 }
-            };
+            });
             perConnCache.put(conn, preparedStatementMap);
         }
         PreparedStatement pstmt = preparedStatementMap.get(getQuery());
@@ -590,5 +593,55 @@ public abstract class AbstractJDBCTestEl
 		}));
 		addPropertiesValues(result, properties);
         return result;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.jmeter.testelement.TestListener#testStarted()
+	 */
+	@Override
+	public void testStarted() {
+		testStarted("");
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.jmeter.testelement.TestListener#testStarted(java.lang.String)
+	 */
+	@Override
+	public void testStarted(String host) {
+		cleanCache();
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.jmeter.testelement.TestListener#testEnded()
+	 */
+	@Override
+	public void testEnded() {
+		testEnded("");
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.jmeter.testelement.TestListener#testEnded(java.lang.String)
+	 */
+	@Override
+	public void testEnded(String host) {
+		cleanCache();		
+	}
+	
+	/**
+	 * Clean cache of PreparedStatements
+	 */
+	private static final void cleanCache() {
+		for (Map.Entry<Connection, Map<String, PreparedStatement>> element : perConnCache.entrySet())
{
+			closeAllStatements(element.getValue().values());
+		}
+		perConnCache.clear();
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.jmeter.testelement.TestListener#testIterationStart(org.apache.jmeter.engine.event.LoopIterationEvent)
+	 */
+	@Override
+	public void testIterationStart(LoopIterationEvent event) {
+		// NOOP
 	}  
 }
\ No newline at end of file

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1224967&r1=1224966&r2=1224967&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Tue Dec 27 18:22:31 2011
@@ -108,6 +108,7 @@ This behaviour can be changed with prope
 <li>Bug 52036 - Durable Subscription fails with ActiveMQ due to missing clientId field</li>
 <li>Bug 52044 - JMS Subscriber used with many threads leads to javax.naming.NamingException:
Something already bound with ActiveMQ</li>
 <li>Bug 52072 - LengthPrefixedBinaryTcpClientImpl may end a sample prematurely</li>
+<li>Bug 52390 - AbstractJDBCTestElement:Memory leak and synchronization issue in perConnCache</li>
 </ul>
 
 <h3>Controllers</h3>



Mime
View raw message