SessionType getSession() throws Exception {
    while (true) {
      SessionType result = null;
      poolLock.lock();
      try {
        while ((result = pool.poll()) == null) {
          LOG.info("Awaiting Tez session to become available in session pool");
          notEmpty.await(10, TimeUnit.SECONDS);
        }
      } finally {
        poolLock.unlock();
      }
      if (result.tryUse(false)) return result;
      LOG.info("Failed to use a session [" + result + "]; attempting another one");
    }
  }
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