public void setTezSession(TezSessionState session) {
    if (tezSessionState == session) {
      return; // The same object.
    }
    if (tezSessionState != null) {
      tezSessionState.markFree();
      tezSessionState.setKillQuery(null);
      tezSessionState = null;
    }
    tezSessionState = session;
    if (session != null) {
      session.markInUse();
      tezSessionState.setKillQuery(getKillQuery());
    }
  }
Called from TezTask to attach a TezSession to use to the threadlocal. Ugly pattern...
ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java