From 23ca6b4facd766db6e30077ebe03a3ff274fa2c7 Mon Sep 17 00:00:00 2001 From: zzz Date: Tue, 25 Sep 2012 19:24:11 +0000 Subject: [PATCH] * SimpleByteCache: Concurrent fix --- core/java/src/net/i2p/util/SimpleByteCache.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/java/src/net/i2p/util/SimpleByteCache.java b/core/java/src/net/i2p/util/SimpleByteCache.java index b41f9ad9b..dae27d80e 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 _caches = new ConcurrentHashMap(8); + private static final ConcurrentHashMap _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;