Package akka.io
Class DirectByteBufferPool
- java.lang.Object
-
- akka.io.DirectByteBufferPool
-
- All Implemented Interfaces:
BufferPool
public class DirectByteBufferPool extends java.lang.Object implements BufferPool
INTERNAL APIA buffer pool which keeps a free list of direct buffers of a specified default size in a simple fixed size stack.
If the stack is full the buffer is de-referenced and available to be freed by normal garbage collection.
Using a direct ByteBuffer when dealing with NIO operations has been proven to be faster than wrapping on-heap Arrays. There is ultimately no performance benefit to wrapping in-heap JVM data when writing with NIO.
-
-
Constructor Summary
Constructors Constructor Description DirectByteBufferPool(int defaultBufferSize, int maxPoolEntries)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.nio.ByteBuffer
acquire()
void
release(java.nio.ByteBuffer buf)
static void
tryCleanDirectByteBuffer(java.nio.ByteBuffer byteBuffer)
DirectByteBuffers are garbage collected by using a phantom reference and a reference queue.
-
-
-
Method Detail
-
tryCleanDirectByteBuffer
public static void tryCleanDirectByteBuffer(java.nio.ByteBuffer byteBuffer)
DirectByteBuffers are garbage collected by using a phantom reference and a reference queue. Every once a while, the JVM checks the reference queue and cleans the DirectByteBuffers. However, as this doesn't happen immediately after discarding all references to a DirectByteBuffer, it's easy to OutOfMemoryError yourself using DirectByteBuffers. This function explicitly calls the Cleaner method of a DirectByteBuffer.Utilizes reflection to avoid dependency to
sun.misc.Cleaner
.- Parameters:
byteBuffer
- (undocumented)
-
acquire
public java.nio.ByteBuffer acquire()
- Specified by:
acquire
in interfaceBufferPool
-
release
public void release(java.nio.ByteBuffer buf)
- Specified by:
release
in interfaceBufferPool
-
-