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 2014/07/26 23:19:00 UTC

svn commit: r1613725 - /jmeter/trunk/src/components/org/apache/jmeter/control/CriticalSectionController.java

Author: pmouawad
Date: Sat Jul 26 21:18:59 2014
New Revision: 1613725

URL: http://svn.apache.org/r1613725
Log:
Bug 56728 - New Critical Section Controller to serialize blocks of a Test
Fix code and javadocs as per sebb notes on dev mailing list
Bugzilla Id: 56728

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/control/CriticalSectionController.java

Modified: jmeter/trunk/src/components/org/apache/jmeter/control/CriticalSectionController.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/control/CriticalSectionController.java?rev=1613725&r1=1613724&r2=1613725&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/control/CriticalSectionController.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/control/CriticalSectionController.java Sat Jul 26 21:18:59 2014
@@ -70,9 +70,9 @@ public class CriticalSectionController e
 
     private static final String LOCK_NAME = "CriticalSectionController.lockName"; //$NON-NLS-1$
 
-    private static final ConcurrentHashMap<String, ReentrantLock> lockMap = new ConcurrentHashMap<String, ReentrantLock>();
+    private static final ConcurrentHashMap<String, ReentrantLock> LOCK_MAP = new ConcurrentHashMap<String, ReentrantLock>();
 
-    private transient ReentrantLock currentLock;
+    private transient volatile ReentrantLock currentLock;
 
     /**
      * constructor
@@ -97,23 +97,25 @@ public class CriticalSectionController e
     }
 
     /**
-     * Function for autocreate and get lock
+     * If lock exists returns it, otherwise creates one, puts it in LOCK_MAP 
+     * then returns it
      * 
-     * @return named lock
+     * @return {@link ReentrantLock}
      */
-    private ReentrantLock getLock() {
-        ReentrantLock lock = lockMap.get(getLockName());
+    private ReentrantLock getOrCreateLock() {
+        String lockName = getLockName();
+        ReentrantLock lock = LOCK_MAP.get(lockName);
         ReentrantLock prev = null;
         if (lock != null) {
             return lock;
         }
         lock = new ReentrantLock();
-        prev = lockMap.putIfAbsent(getLockName(), lock);
+        prev = LOCK_MAP.putIfAbsent(lockName, lock);
         return prev == null ? lock : prev;
     }
 
     /**
-     * Lock name
+     * @return String lock name
      */
     public String getLockName() {
         return getPropertyAsString(LOCK_NAME);
@@ -133,7 +135,7 @@ public class CriticalSectionController e
             // Take the lock for first child element
             long startTime = System.currentTimeMillis();
             if (this.currentLock == null) {
-                this.currentLock = getLock();
+                this.currentLock = getOrCreateLock();
             }
             this.currentLock.lock();
             long endTime = System.currentTimeMillis();
@@ -191,7 +193,7 @@ public class CriticalSectionController e
 
     @Override
     public void testEnded() {
-        lockMap.clear();
+        LOCK_MAP.clear();
     }
 
     @Override