Class RecyclingBufferPool

  • All Implemented Interfaces:
    BufferPool

    public class RecyclingBufferPool
    extends java.lang.Object
    implements BufferPool
    A pool of buffers which uses a simple reference queue to recycle buffers. Do not use it as generic buffer pool - it is optimized and supports only buffer sizes used by the Zstd classes.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int buffSize  
      static BufferPool INSTANCE  
      private java.util.Deque<java.lang.ref.SoftReference<java.nio.ByteBuffer>> pool  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private RecyclingBufferPool()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.nio.ByteBuffer get​(int capacity)
      Fetch a buffer from the pool.
      void release​(java.nio.ByteBuffer buffer)
      Return a buffer to the pool.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INSTANCE

        public static final BufferPool INSTANCE
      • buffSize

        private static final int buffSize
      • pool

        private final java.util.Deque<java.lang.ref.SoftReference<java.nio.ByteBuffer>> pool
    • Constructor Detail

      • RecyclingBufferPool

        private RecyclingBufferPool()
    • Method Detail

      • get

        public java.nio.ByteBuffer get​(int capacity)
        Description copied from interface: BufferPool
        Fetch a buffer from the pool.
        Specified by:
        get in interface BufferPool
        Parameters:
        capacity - the desired size of the buffer
        Returns:
        a heap buffer with size at least the `capacity` and arrayOffset of 0
      • release

        public void release​(java.nio.ByteBuffer buffer)
        Description copied from interface: BufferPool
        Return a buffer to the pool.
        Specified by:
        release in interface BufferPool
        Parameters:
        buffer - the buffer to return