Class ConcurrentResourcePool<T>

  • All Implemented Interfaces:
    java.lang.Iterable<T>

    public class ConcurrentResourcePool<T>
    extends java.lang.Object
    implements java.lang.Iterable<T>
    A pool of a resource. This create new instances of the resource on request until enough are created to deliver a unique one to all threads needing one concurrently and then reuse those instances in subsequent requests.
    Author:
    baldersheim
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      T alloc()
      Allocates an instance of the resource to the requestor.
      void free​(T e)
      Frees an instance previously acquired bty alloc
      java.util.Iterator<T> iterator()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • ConcurrentResourcePool

        public ConcurrentResourcePool​(ResourceFactory<T> factory)
      • ConcurrentResourcePool

        public ConcurrentResourcePool​(java.util.function.Supplier<T> factory)
    • Method Detail

      • alloc

        public final T alloc()
        Allocates an instance of the resource to the requestor. The resource will be allocated exclusively to the requestor until it calls free(instance).
        Returns:
        a reused or newly created instance of the resource
      • free

        public final void free​(T e)
        Frees an instance previously acquired bty alloc
      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<T>