private void free(ByteBuffer oldBuf) { if ((oldBuf == null) || ((maxCachedBufferSize != 0) && (oldBuf.capacity() > maxCachedBufferSize)) || oldBuf.isReadOnly() || isDerived() || (Thread.currentThread() != ownerThread)) { return; } // Add to the cache. Queue<CachedBuffer> pool; if (oldBuf.isDirect()) { pool = directBuffers.get().get(oldBuf.capacity()); } else { pool = heapBuffers.get().get(oldBuf.capacity()); } if (pool == null) { return; } // Restrict the size of the pool to prevent OOM. if ((maxPoolSize == 0) || (pool.size() < maxPoolSize)) { pool.offer(new CachedBuffer(oldBuf)); } } }
private void free(ByteBuffer oldBuf) { if (oldBuf == null || oldBuf.capacity() > maxCachedBufferSize || oldBuf.isReadOnly() || isDerived() || Thread.currentThread() != ownerThread) { return; } // Add to the cache. Queue<CachedBuffer> pool; if (oldBuf.isDirect()) { pool = directBuffers.get().get(oldBuf.capacity()); } else { pool = heapBuffers.get().get(oldBuf.capacity()); } if (pool == null) { return; } // Restrict the size of the pool to prevent OOM. if (maxPoolSize == 0 || pool.size() < maxPoolSize) { pool.offer(new CachedBuffer(oldBuf)); } } }
private void free(ByteBuffer oldBuf) { if ((oldBuf == null) || ((maxCachedBufferSize != 0) && (oldBuf.capacity() > maxCachedBufferSize)) || oldBuf.isReadOnly() || isDerived() || (Thread.currentThread() != ownerThread)) { return; } // Add to the cache. Queue<CachedBuffer> pool; if (oldBuf.isDirect()) { pool = directBuffers.get().get(oldBuf.capacity()); } else { pool = heapBuffers.get().get(oldBuf.capacity()); } if (pool == null) { return; } // Restrict the size of the pool to prevent OOM. if ((maxPoolSize == 0) || (pool.size() < maxPoolSize)) { pool.offer(new CachedBuffer(oldBuf)); } } }