Interface Pool<P>

Type Parameters:
P - the type of the pooled objects
All Known Implementing Classes:
CompoundPool, ConcurrentPool, LockedPool, Pool.Wrapper, QueuedPool

@ManagedObject public interface Pool<P>

A pool of objects, with support for multiplexing and several optimized strategies plus an optional ThreadLocal cache of the last released entry.

A Pool should be terminated when it is no longer needed; once terminated, it cannot be used anymore.

  • Method Details

    • reserve

      Pool.Entry<P> reserve()

      Creates a new disabled slot into the pool.

      The returned entry must ultimately have the Pool.Entry.enable(Object, boolean) method called or be removed via Pool.Entry.remove().

      Returns:
      a disabled entry that is contained in the pool, or null if the pool is terminated or if the pool cannot reserve an entry
    • acquire

      Pool.Entry<P> acquire()

      Acquires an entry from the pool.

      Only enabled entries will be returned from this method and their Pool.Entry.enable(Object, boolean) method must not be called.

      Returns:
      an entry from the pool or null if none is available.
    • acquire

      default Pool.Entry<P> acquire(Function<Pool.Entry<P>,P> creator)

      Acquires an entry from the pool, reserving and creating a new entry if necessary.

      Parameters:
      creator - a function to create the pooled value for a reserved entry.
      Returns:
      an entry from the pool or null if none is available.
    • isTerminated

      boolean isTerminated()
      Returns:
      whether this Pool has been terminated
      See Also:
    • terminate

      Collection<Pool.Entry<P>> terminate()

      Terminates this Pool.

      All the entries are marked as terminated and cannot be acquired nor released, but only removed.

      The returned list of all entries may be iterated to perform additional operations on the pooled objects.

      The pool cannot be used anymore after it is terminated.

      Returns:
      a list of all entries
    • size

      @ManagedAttribute("The number of entries") int size()
      Returns:
      the current number of entries in this Pool
    • getMaxSize

      @ManagedAttribute("The maximum number of entries") int getMaxSize()
      Returns:
      the maximum number of entries in this Pool
    • stream

      Stream<Pool.Entry<P>> stream()
      Returns:
      a Stream over the entries
    • getReservedCount

      @ManagedAttribute("The number of reserved entries") default int getReservedCount()
      Returns:
      the number of reserved entries
    • getIdleCount

      @ManagedAttribute("The number of idle entries") default int getIdleCount()
      Returns:
      the number of idle entries
    • getInUseCount

      @ManagedAttribute("The number of in-use entries") default int getInUseCount()
      Returns:
      the number of in-use entries
    • getTerminatedCount

      @ManagedAttribute("The number of terminated entries") default int getTerminatedCount()
      Returns:
      the number of terminated entries