forked from phoedos/pmd
[core] Use concurrent hash map in ParameterizedMetricKey
This commit is contained in:
@ -4,8 +4,8 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.metrics;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import net.sourceforge.pmd.annotation.InternalApi;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
@ -24,7 +24,7 @@ import net.sourceforge.pmd.util.DataMap.DataKey;
|
||||
@Deprecated
|
||||
public final class ParameterizedMetricKey<N extends Node> implements DataKey<ParameterizedMetricKey<N>, Double> {
|
||||
|
||||
private static final Map<ParameterizedMetricKey<?>, ParameterizedMetricKey<?>> POOL = new HashMap<>();
|
||||
private static final ConcurrentMap<ParameterizedMetricKey<?>, ParameterizedMetricKey<?>> POOL = new ConcurrentHashMap<>();
|
||||
|
||||
/** The metric key. */
|
||||
public final MetricKey<N> key;
|
||||
@ -72,9 +72,7 @@ public final class ParameterizedMetricKey<N extends Node> implements DataKey<Par
|
||||
public static <N extends Node> ParameterizedMetricKey<N> getInstance(MetricKey<N> key, MetricOptions options) {
|
||||
// sharing instances allows using DataMap, which uses reference identity
|
||||
ParameterizedMetricKey<N> tmp = new ParameterizedMetricKey<>(key, options);
|
||||
if (!POOL.containsKey(tmp)) {
|
||||
POOL.put(tmp, tmp);
|
||||
}
|
||||
POOL.putIfAbsent(tmp, tmp);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ParameterizedMetricKey<N> result = (ParameterizedMetricKey<N>) POOL.get(tmp);
|
||||
|
Reference in New Issue
Block a user