public boolean tryExpire(boolean isAsync) throws Exception {
    if (expirationNs == null) return true;
    if (!shouldExpire()) return false;
    // Try to expire the session if it's not in use; if in use, bail.
    while (true) {
      if (sessionState.get() != STATE_NONE) return true; // returnAfterUse will take care of this
      if (sessionState.compareAndSet(STATE_NONE, STATE_EXPIRED)) {
        if (isAsync) {
          expirationTracker.closeAndRestartExpiredSessionAsync(this);
        } else {
          expirationTracker.closeAndRestartExpiredSession(this);
        }
        return true;
      }
    }
  }
Tries to expire and restart the session.
@param isAsync Whether the restart should happen asynchronously.
@return True if the session was, or will be restarted.
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionPoolSession.java