#88: Applied a patch from @ewencp to fix missing reference problem of CachedBufferAllocator

This commit is contained in:
Taro L. Saito 2014-10-22 09:53:13 +09:00
parent 7b86642f75
commit dfc9322a5b
1 changed files with 9 additions and 3 deletions

View File

@ -29,10 +29,16 @@ public class CachedBufferAllocator implements BufferAllocator {
} }
public static synchronized CachedBufferAllocator getAllocator(int bufferSize) { public static synchronized CachedBufferAllocator getAllocator(int bufferSize) {
if(!queueTable.containsKey(bufferSize)) { CachedBufferAllocator result = null;
queueTable.put(bufferSize, new SoftReference<CachedBufferAllocator>(new CachedBufferAllocator(bufferSize)));
if (queueTable.containsKey(bufferSize)) {
result = queueTable.get(bufferSize).get();
} }
return queueTable.get(bufferSize).get(); if (result == null) {
result = new CachedBufferAllocator(bufferSize);
queueTable.put(bufferSize, new SoftReference<CachedBufferAllocator>(result));
}
return result;
} }
@Override @Override