ListenableFuture<SessionType> getSessionAsync() throws Exception {
    SettableFuture<SessionType> future = SettableFuture.create();
    poolLock.lock();
    try {
      // Try to get the session quickly.
      while (true) {
        SessionType result = pool.poll();
        if (result == null) break;
        if (!result.tryUse(false)) continue;
        future.set(result);
        return future;
      }
      // The pool is empty; queue the request.
      asyncRequests.add(future);
      return future;
    } finally {
      poolLock.unlock();
    }
  }
The number of sessions that needs to be started or killed because of the resize calls on
the pool. When increasing the size, we set this to a positive number and start new sessions
on background threads, gradually bringing it back to 0.
When decreasing the size, we try to kill as many existing sessions as we can; if that is
not enough because the sessions are in use or being restarted, we kill them as they are
re-added to the pool.
Repeated calls to resize adjust the delta to ensure correctness between different resizes.
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionPool.java