Interface ByteBufferPool
public interface ByteBufferPool
Object Pool that allows to borrow and release
ByteBuffers according to a specific type (direct/heap).
The suggested usage pattern is:
ByteBuffer buffer = pool.borrow(size);
//...using buffer...
pool.release(buffer);
-
Method Summary
Modifier and TypeMethodDescriptionborrow(int size, boolean zeroed) voidrelease(ByteBuffer buffer) It pools or freebufferthat cannot be used anymore.static ByteBufferPoolthreadLocal(boolean direct) Factory method that creates a thread-local pool of capacity 1 ofByteBuffers of the specified type (direct/heap).
-
Method Details
-
borrow
It returns aByteBufferwithBuffer.capacity()>=size.The
bufferis zeroed untilsizeifzeroed=true, withBuffer.position()=0 andBuffer.limit()=size. -
release
It pools or freebufferthat cannot be used anymore.If
bufferis of a type different from the one that the pool can borrow, it will ignore it. -
threadLocal
Factory method that creates a thread-local pool of capacity 1 ofByteBuffers of the specified type (direct/heap).
-