code: private void returnResource(T t, boolean isValid) {
          if (!isValid) {
              handleInvalid(t);
          } else {
              WaitingRequest<T> waiting;
              boolean toDestroy = false;
              synchronized (lock) {
                  waiting = waitQueue.poll();
                  if (waiting == null) {
                      if (!isRunning) {
                          // The resource will be closed if returned anytime after the shutdown has been initiated.
                          resourceCount--;
                          toDestroy = true;
                      } else {
                          // as resources are returned to us, we put them in queue to be reused
                          // if returned resource increases our idle resource count, do not include it
                          if (idleResources.size() < maxIdle) {
                              idleResources.offer(t);
                          } else {
                              resourceCount--;
                              toDestroy = true;
                          }
                      }
                  }
              }
  
              if (waiting != null) {
                  waiting.future.complete(new CloseableResource<>(t, this));
              }
  
              if (toDestroy) {
                  if (listener != null) {
                      listener.notify(Event.Destroyed);
                  }
                  tDestroyer.accept(t);
              }
          }
      }
docs: Method to return resource back to the pool. Callers are expected to call close on the closableResource which in turn
  calls the return resource method to return the resource to the pool so that it can be reused.
  
  @param t resource to be returned
  @param isValid is resource valid