Interface Pooled<E>

Type Parameters:
E - The type of the wrapped object.
All Superinterfaces:
AutoCloseable

public interface Pooled<E> extends AutoCloseable
The Pooled interface represents a wrapper around an object that can be returned to a pool after use.

Pooled objects are AutoCloseable for convenience, e.g. usage in try-with-resources statements.

Since:
1.8
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Equivalent to free() for convenience.
    void
    Returns the object back to the pool, making it available for reuse.
    get()
    Retrieves the underlying object managed by this Pooled instance.
  • Method Details

    • get

      E get()
      Retrieves the underlying object managed by this Pooled instance.
      Returns:
      The object of type E.
    • free

      void free()
      Returns the object back to the pool, making it available for reuse.

      Either this method or, equivalently, close() should be called when the object is no longer needed by the caller.

      Do not call this method multiple times. That also means you should call either free or close, never both. Implementations may detect this and throw some exception, but can typically not do that reliably.

    • close

      default void close()
      Equivalent to free() for convenience.
      Specified by:
      close in interface AutoCloseable