You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2012/08/19 23:47:53 UTC

svn commit: r1374861 - /jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java

Author: pmouawad
Date: Sun Aug 19 21:47:53 2012
New Revision: 1374861

URL: http://svn.apache.org/viewvc?rev=1374861&view=rev
Log:
Fix ConcurrentModificationException that happens when you stop a test while it's in rampup period.

This was due to race condition between the groups.clear() and StopThread calling one of the methods that iterates on groups in a for each.


Modified:
    jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java?rev=1374861&r1=1374860&r2=1374861&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/engine/StandardJMeterEngine.java Sun Aug 19 21:47:53 2012
@@ -21,12 +21,12 @@ package org.apache.jmeter.engine;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Properties;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.apache.jmeter.JMeter;
 import org.apache.jmeter.testbeans.TestBean;
@@ -104,7 +104,7 @@ public class StandardJMeterEngine implem
     private final String host;
 
     // The list of current thread groups; may be setUp, main, or tearDown.
-    private final List<AbstractThreadGroup> groups = Collections.synchronizedList(new ArrayList<AbstractThreadGroup>());
+    private final List<AbstractThreadGroup> groups = new CopyOnWriteArrayList<AbstractThreadGroup>();
 
     public static void stopEngineNow() {
         if (engine != null) {// May be null if called from Unit test
@@ -365,7 +365,7 @@ public class StandardJMeterEngine implem
             JMeterContextService.clearTotalThreads();
         }
 
-        groups.clear(); // The groups have all completed now
+        groups.clear(); // The groups have all completed now                
 
         /*
          * Here's where the test really starts. Run a Full GC now: it's no harm
@@ -404,8 +404,7 @@ public class StandardJMeterEngine implem
 
         //wait for all Test Threads To Exit
         waitThreadsStopped();
-
-        groups.clear(); // The groups have all completed now
+        groups.clear(); // The groups have all completed now            
 
         if (postIter.hasNext()){
             groupCount = 0;
@@ -435,7 +434,7 @@ public class StandardJMeterEngine implem
         int reminingThreads= 0;
         for (AbstractThreadGroup threadGroup : groups) {
             reminingThreads += threadGroup.numberOfActiveThreads();
-        }
+        }            
         return reminingThreads; 
     }