diff --git a/core/java/src/net/i2p/util/SimpleByteCache.java b/core/java/src/net/i2p/util/SimpleByteCache.java index b41f9ad9b5bf87acedd4aebd7ad8d591b262732f..dae27d80e12e7f71dd0f620da9f58c75e867e295 100644 --- a/core/java/src/net/i2p/util/SimpleByteCache.java +++ b/core/java/src/net/i2p/util/SimpleByteCache.java @@ -16,7 +16,7 @@ import java.util.concurrent.LinkedBlockingQueue; */ public final class SimpleByteCache { - private static final Map<Integer, SimpleByteCache> _caches = new ConcurrentHashMap(8); + private static final ConcurrentHashMap<Integer, SimpleByteCache> _caches = new ConcurrentHashMap(8); private static final int DEFAULT_SIZE = 64; @@ -45,7 +45,9 @@ public final class SimpleByteCache { SimpleByteCache cache = _caches.get(sz); if (cache == null) { cache = new SimpleByteCache(cacheSize, size); - _caches.put(sz, cache); + SimpleByteCache old = _caches.putIfAbsent(sz, cache); + if (old != null) + cache = old; } cache.resize(cacheSize); return cache;