Class Recycler<T extends AutoCloseable,E extends Exception>

  • All Implemented Interfaces:
    AutoCloseable

    public abstract class Recycler<T extends AutoCloseable,E extends Exception>
    extends Object
    implements AutoCloseable
    Recycle instances of type T. The method T#close() is called when this class' own close() method is called. Use RuntimeException for type E if the newInstance() method does not throw an exception.
    • Constructor Detail

      • Recycler

        public Recycler()
    • Method Detail

      • acquire

        public T acquire()
                  throws E extends Exception
        Acquire or allocate an instance.
        Throws:
        E extends Exception
      • release

        public void release​(T instance)
        Release/recycle an instance.
      • close

        public void close()
        Call this only after all instances have been released.
        Specified by:
        close in interface AutoCloseable
      • newInstance

        public abstract T newInstance()
                               throws E extends Exception
        Create a new instance.
        Throws:
        E extends Exception