diff --git a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/data/ParamMapBucket.java b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/data/ParamMapBucket.java index 05ef13c8..24e1d1d0 100644 --- a/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/data/ParamMapBucket.java +++ b/sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/slots/statistic/data/ParamMapBucket.java @@ -59,9 +59,16 @@ public class ParamMapBucket { } public ParamMapBucket add(RollingParamEvent event, int count, Object value) { - data[event.ordinal()].putIfAbsent(value, new AtomicInteger()); AtomicInteger counter = data[event.ordinal()].get(value); - counter.addAndGet(count); + // Note: not strictly concise. + if (counter == null) { + AtomicInteger old = data[event.ordinal()].putIfAbsent(value, new AtomicInteger(count)); + if (old != null) { + old.addAndGet(count); + } + } else { + counter.addAndGet(count); + } return this; } @@ -74,4 +81,4 @@ public class ParamMapBucket { } public static final int DEFAULT_MAX_CAPACITY = 200; -} +} \ No newline at end of file