public T acquire ( ) throws E { final T instance ; final T recycledInstance = unusedInstances . poll ( ) ; if ( recycledInstance == null ) { // Allocate a new instance -- may throw an exception of type E final T newInstance = newInstance ( ) ; if ( newInstance == null ) { throw new NullPointerException ( "Failed to allocate a new recyclable instance" ) ; } instance = newInstance ; } else { // Reuse an unused instance instance = recycledInstance ; } usedInstances . add ( instance ) ; return instance ; }
Acquire on object instance of type T either by reusing a previously recycled instance if possible or if there are no currently - unused instances by allocating a new instance .