Author: sebb
Date: Sat Dec 11 00:01:41 2010
New Revision: 1044544
URL: http://svn.apache.org/viewvc?rev=1044544&view=rev
Log:
Use putIfAbsent() instead of synch. on ConcurrentHashMap
Modified:
jakarta/jmeter/trunk/src/components/org/apache/jmeter/timers/ConstantThroughputTimer.java
Modified:
jakarta/jmeter/trunk/src/components/org/apache/jmeter/timers/ConstantThroughputTimer.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/components/org/apache/jmeter/timers/ConstantThroughputTimer.java?rev=1044544&r1=1044543&r2=1044544&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/components/org/apache/jmeter/timers/ConstantThroughputTimer.java
(original)
+++
jakarta/jmeter/trunk/src/components/org/apache/jmeter/timers/ConstantThroughputTimer.java
Sat Dec 11 00:01:41 2010
@@ -18,8 +18,8 @@
package org.apache.jmeter.timers;
-import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
import org.apache.jmeter.engine.event.LoopIterationEvent;
import org.apache.jmeter.testbeans.TestBean;
@@ -71,7 +71,7 @@ public class ConstantThroughputTimer ext
private final static ThroughputInfo allThreadsInfo = new ThroughputInfo();
//For holding the ThrougputInfo objects for all ThreadGroups. Keyed by
AbstractThreadGroup objects
- private final static Map<AbstractThreadGroup, ThroughputInfo>
threadGroupsInfoMap =
+ private final static ConcurrentMap<AbstractThreadGroup, ThroughputInfo>
threadGroupsInfoMap =
new ConcurrentHashMap<AbstractThreadGroup, ThroughputInfo>();
@@ -168,11 +168,12 @@ public class ConstantThroughputTimer ext
final org.apache.jmeter.threads.AbstractThreadGroup group =
JMeterContextService.getContext().getThreadGroup();
ThroughputInfo groupInfo;
- synchronized (threadGroupsInfoMap) {
- groupInfo = threadGroupsInfoMap.get(group);
- if (groupInfo == null) {
- groupInfo = new ThroughputInfo();
- threadGroupsInfoMap.put(group, groupInfo);
+ groupInfo = threadGroupsInfoMap.get(group);
+ if (groupInfo == null) {
+ groupInfo = new ThroughputInfo();
+ ThroughputInfo previous =
threadGroupsInfoMap.putIfAbsent(group, groupInfo);
+ if (previous != null) { // We did not replace the entry
+ groupInfo = previous; // so use the existing one
}
}
delay = calculateSharedDelay(groupInfo,(long) msPerRequest);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]