jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1380045 - /jmeter/trunk/src/core/org/apache/jmeter/threads/AbstractThreadGroup.java
Date Sun, 02 Sep 2012 20:18:37 GMT
Author: pmouawad
Date: Sun Sep  2 20:18:37 2012
New Revision: 1380045

URL: http://svn.apache.org/viewvc?rev=1380045&view=rev
Log:
Use AtomicInteger instead of synchronization

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/threads/AbstractThreadGroup.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/threads/AbstractThreadGroup.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/threads/AbstractThreadGroup.java?rev=1380045&r1=1380044&r2=1380045&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/threads/AbstractThreadGroup.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/threads/AbstractThreadGroup.java Sun Sep  2 20:18:37
2012
@@ -21,6 +21,7 @@ package org.apache.jmeter.threads;
 import java.io.Serializable;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.jmeter.control.Controller;
 import org.apache.jmeter.control.LoopController;
@@ -73,8 +74,7 @@ public abstract class AbstractThreadGrou
 
     public static final String MAIN_CONTROLLER = "ThreadGroup.main_controller";
 
-    // @GuardedBy("this")
-    private int numberOfThreads = 0; // Number of active threads in this group
+    private final AtomicInteger numberOfThreads = new AtomicInteger(0); // Number of active
threads in this group
 
     /** {@inheritDoc} */
     public boolean isDone() {
@@ -92,8 +92,7 @@ public abstract class AbstractThreadGrou
      * @return the sampler controller.
      */
     public Controller getSamplerController() {
-        Controller c = (Controller) getProperty(MAIN_CONTROLLER).getObjectValue();
-        return c;
+        return (Controller) getProperty(MAIN_CONTROLLER).getObjectValue();
     }
 
     /**
@@ -175,22 +174,22 @@ public abstract class AbstractThreadGrou
     /**
      * Increment the number of active threads
      */
-    synchronized void incrNumberOfThreads() {
-        numberOfThreads++;
+    void incrNumberOfThreads() {
+        numberOfThreads.incrementAndGet();
     }
 
     /**
      * Decrement the number of active threads
      */
-    synchronized void decrNumberOfThreads() {
-        numberOfThreads--;
+    void decrNumberOfThreads() {
+        numberOfThreads.decrementAndGet();
     }
 
     /**
      * Get the number of active threads
      */
-    public synchronized int getNumberOfThreads() {
-        return numberOfThreads;
+    public int getNumberOfThreads() {
+        return numberOfThreads.get();
     }
     
     /**



Mime
View raw message