Class BufferPoolImpl

  • All Implemented Interfaces:
    BufferPool

    class BufferPoolImpl
    extends java.lang.Object
    implements BufferPool
    char[] pool that pool instances of char[] which are expensive to create.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.ref.WeakReference<java.util.concurrent.ConcurrentLinkedQueue<char[]>> queue  
    • Constructor Summary

      Constructors 
      Constructor Description
      BufferPoolImpl()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.util.concurrent.ConcurrentLinkedQueue<char[]> getQueue()  
      void recycle​(char[] t)
      Returns an object back to the pool.
      char[] take()
      Gets a new object from the pool.
      • Methods inherited from class java.lang.Object

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

      • queue

        private volatile java.lang.ref.WeakReference<java.util.concurrent.ConcurrentLinkedQueue<char[]>> queue
    • Constructor Detail

      • BufferPoolImpl

        BufferPoolImpl()
    • Method Detail

      • take

        public final char[] take()
        Gets a new object from the pool.

        If no object is available in the pool, this method creates a new one.

        Specified by:
        take in interface BufferPool
        Returns:
        always non-null.
      • getQueue

        private java.util.concurrent.ConcurrentLinkedQueue<char[]> getQueue()
      • recycle

        public final void recycle​(char[] t)
        Returns an object back to the pool.
        Specified by:
        recycle in interface BufferPool