Expunge stale entries on computeIfAbsent
@@ -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();
