protected void releaseInstance(T instance) throws IOException {
    AtomicInteger currentCount = providedVsCount.get(instance);
    if(currentCount != null) {
      if(currentCount.decrementAndGet() < 0) {
        currentCount.incrementAndGet();
        throw new IllegalArgumentException("Given instance of " + instance.getClass().getName() + " is not managed by this provider");
      }
    } else {
      throw new IllegalArgumentException("Given instance of " + instance.getClass().getName() + " is not managed by this provider");
    }

    if(instantiated.remove(instance) && instance instanceof Closeable) {
      ((Closeable)instance).close();
    }
  }
protected void releaseInstance ( T instance ) throws IOException { AtomicInteger currentCount = providedVsCount . get ( instance ) ; if ( currentCount != null ) { if ( currentCount . decrementAndGet ( ) < 0 ) { currentCount . incrementAndGet ( ) ; throw new IllegalArgumentException ( "Given instance of " + instance . getClass ( ) . getName ( ) + " is not managed by this provider" ) ; } } else { throw new IllegalArgumentException ( "Given instance of " + instance . getClass ( ) . getName ( ) + " is not managed by this provider" ) ; } if ( instantiated . remove ( instance ) && instance instanceof Closeable ) { ( ( Closeable ) instance ) . close ( ) ; } }
If the instance is provided by the user, {@link Closeable#close()}
will not be invoked.