diff --git a/extensions-core/lookups-cached-global/src/main/java/io/druid/server/lookup/namespace/cache/OnHeapNamespaceExtractionCacheManager.java b/extensions-core/lookups-cached-global/src/main/java/io/druid/server/lookup/namespace/cache/OnHeapNamespaceExtractionCacheManager.java
index e69754b01c1..ed271855796 100644
--- a/extensions-core/lookups-cached-global/src/main/java/io/druid/server/lookup/namespace/cache/OnHeapNamespaceExtractionCacheManager.java
+++ b/extensions-core/lookups-cached-global/src/main/java/io/druid/server/lookup/namespace/cache/OnHeapNamespaceExtractionCacheManager.java
@@ -28,8 +28,10 @@ import io.druid.java.util.common.lifecycle.Lifecycle;
import io.druid.java.util.common.logger.Logger;
import java.lang.ref.WeakReference;
+import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -48,8 +50,9 @@ public class OnHeapNamespaceExtractionCacheManager extends NamespaceExtractionCa
*
{@link WeakReference} doesn't override Object's identity equals() and hashCode(), so effectively this map plays
* like concurrent {@link java.util.IdentityHashMap}.
*/
- private final ConcurrentHashMap>, Boolean> caches =
- new ConcurrentHashMap<>();
+ private final Set>> caches = Collections.newSetFromMap(
+ new ConcurrentHashMap>, Boolean>()
+ );
@Inject
public OnHeapNamespaceExtractionCacheManager(Lifecycle lifecycle, ServiceEmitter serviceEmitter)
@@ -59,8 +62,7 @@ public class OnHeapNamespaceExtractionCacheManager extends NamespaceExtractionCa
private void expungeCollectedCaches()
{
- for (Iterator>> iterator = caches.keySet().iterator();
- iterator.hasNext(); ) {
+ for (Iterator>> iterator = caches.iterator(); iterator.hasNext(); ) {
WeakReference> cacheRef = iterator.next();
if (cacheRef.get() == null) {
// This may not necessarily mean leak of CacheHandler, because disposeCache() may be called concurrently with
@@ -81,7 +83,7 @@ public class OnHeapNamespaceExtractionCacheManager extends NamespaceExtractionCa
ConcurrentMap cache = new ConcurrentHashMap<>();
WeakReference> cacheRef = new WeakReference<>(cache);
expungeCollectedCaches();
- caches.put(cacheRef, true);
+ caches.add(cacheRef);
return new CacheHandler(this, cache, cacheRef);
}
@@ -107,7 +109,7 @@ public class OnHeapNamespaceExtractionCacheManager extends NamespaceExtractionCa
long numEntries = 0;
long size = 0;
expungeCollectedCaches();
- for (WeakReference> cacheRef : caches.keySet()) {
+ for (WeakReference> cacheRef : caches) {
final Map cache = cacheRef.get();
if (cache == null) {
continue;