Class ConcurrentPool<T>


  • public class ConcurrentPool<T>
    extends java.lang.Object
    A concurrent pool implementation.

    This class should not be considered a part of the public API.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Clears the pool of all objects.
      void ensureMinSize​(int minSize, boolean initialize)  
      T get()
      Gets an object from the pool.
      T get​(long timeout, java.util.concurrent.TimeUnit timeUnit)
      Gets an object from the pool - will block if none are available
      int getAvailableCount()  
      int getCount()  
      int getInUseCount()  
      int getMaxSize()  
      void prune()  
      void release​(T t)
      Return an instance of T to the pool.
      void release​(T t, boolean prune)
      call done when you are done with an object from the pool if there is room and the object is ok will get added
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ConcurrentPool

        public ConcurrentPool​(int maxSize,
                              ConcurrentPool.ItemFactory<T> itemFactory)
        Initializes a new pool of objects.
        Parameters:
        maxSize - max to hold to at any given time. if < 0 then no limit
        itemFactory - factory used to create and close items in the pool
    • Method Detail

      • release

        public void release​(T t)
        Return an instance of T to the pool. This method simply calls release(t, false)
        Parameters:
        t - item to return to the pool
      • release

        public void release​(T t,
                            boolean prune)
        call done when you are done with an object from the pool if there is room and the object is ok will get added
        Parameters:
        t - item to return to the pool
        prune - true if the item should be closed, false if it should be put back in the pool
      • get

        public T get()
        Gets an object from the pool. This method will block until a permit is available.
        Returns:
        An object from the pool.
      • get

        public T get​(long timeout,
                     java.util.concurrent.TimeUnit timeUnit)
        Gets an object from the pool - will block if none are available
        Parameters:
        timeout - negative - forever 0 - return immediately no matter what positive ms to wait
        timeUnit - the time unit of the timeout
        Returns:
        An object from the pool, or null if can't get one in the given waitTime
        Throws:
        MongoTimeoutException - if the timeout has been exceeded
      • prune

        public void prune()
      • ensureMinSize

        public void ensureMinSize​(int minSize,
                                  boolean initialize)
      • close

        public void close()
        Clears the pool of all objects.
      • getMaxSize

        public int getMaxSize()
      • getInUseCount

        public int getInUseCount()
      • getAvailableCount

        public int getAvailableCount()
      • getCount

        public int getCount()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object