Expunge stale entries on computeIfAbsent
MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/cache/weaklockfree/WeakConcurrentMap.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/cache/weaklockfree/WeakConcurrentMap.java
@@ -30,6 +30,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Function;
import javax.annotation.Nullable;
/**
@@ -243,6 +244,12 @@ public class WeakConcurrentMap<K, V>
return super.putIfAbsent(key, value);
}
+ @Override
+ public V computeIfAbsent(K key, Function<? super K, ? extends V> mappingFunction) {
+ expungeStaleEntries();
+ return super.computeIfAbsent(key, mappingFunction);
+ }
+
@Override
public V remove(K key) {
expungeStaleEntries();

Expunge stale entries on computeIfAbsent (#6235)