code: @Override
    public T acquire(long time, TimeUnit unit) throws TimeoutException, IOException {
      long endTimeMs = mClock.millis() + unit.toMillis(time);
  
      // Try to take a resource without blocking
      ResourceInternal<T> resource = poll();
      if (resource != null) {
        return checkHealthyAndRetry(resource.mResource, endTimeMs);
      }
  
      if (!isFull()) {
        // If the resource pool is empty but capacity is not yet full, create a new resource.
        T newResource = createNewResource();
        ResourceInternal<T> resourceInternal = new ResourceInternal<>(newResource);
        if (add(resourceInternal)) {
          return newResource;
        } else {
          closeResource(newResource);
        }
      }
  
      // Otherwise, try to take a resource from the pool, blocking if none are available.
      try {
        mLock.lock();
        while (true) {
          resource = poll();
          if (resource != null) {
            break;
          }
          long currTimeMs = mClock.millis();
          try {
            // one should use t1-t0<0, not t1<t0, because of the possibility of numerical overflow.
            // For further detail see: https://docs.oracle.com/javase/8/docs/api/java/lang/System.html
            if (endTimeMs - currTimeMs <= 0 || !mNotEmpty
                .await(endTimeMs - currTimeMs, TimeUnit.MILLISECONDS)) {
              throw new TimeoutException("Acquire resource times out.");
            }
          } catch (InterruptedException e) {
            // Restore the interrupt flag so that it can be handled later.
            Thread.currentThread().interrupt();
          }
        }
      } finally {
        mLock.unlock();
      }
  
      return checkHealthyAndRetry(resource.mResource, endTimeMs);
    }
docs: Acquires a resource of type {code T} from the pool.
  
  This method is like {@link #acquire()}, but it will time out if an object cannot be
  acquired before the specified amount of time.
  
  @param time an amount of time to wait
  @param unit the unit to use for time
  @return a resource taken from the pool
  @throws TimeoutException if it fails to acquire because of time out