changeset 1205:a494b191404e

7901398: Deduplicator is not thread-safe Contributed-by: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
author shade
date Wed, 22 Apr 2015 22:33:59 +0300
parents 49b2a7f6cc8a
children f0d8b3a09c00
files jmh-core/src/main/java/org/openjdk/jmh/util/Deduplicator.java
diffstat 1 files changed, 3 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/Deduplicator.java	Fri Apr 17 13:17:37 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/Deduplicator.java	Wed Apr 22 22:33:59 2015 +0300
@@ -24,23 +24,22 @@
  */
 package org.openjdk.jmh.util;
 
-import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 public class Deduplicator<T> {
 
     final Map<T, T> map;
 
     public Deduplicator() {
-        map = new HashMap<T, T>();
+        map = new ConcurrentHashMap<T, T>();
     }
 
     public T dedup(T t) {
-        T et = map.get(t);
+        T et = map.putIfAbsent(t, t);
         if (et != null) {
             return et;
         } else {
-            map.put(t, t);
             return t;
         }
     }