private synchronized void acquireAfterOpLock(boolean userAccess) {
    // Need to make sure that the this HiveServer2's session's SessionState is
    // stored in the thread local for the handler thread.
    SessionState.setCurrentSessionState(sessionState);
    sessionState.setForwardedAddresses(SessionManager.getForwardedAddresses());
    sessionState.setIsUsingThriftJDBCBinarySerDe(updateIsUsingThriftJDBCBinarySerDe());
    if (userAccess) {
      lastAccessTime = System.currentTimeMillis();
      lockedByUser = true;
    }
    // set the thread name with the logging prefix.
    sessionState.updateThreadName();

    // If Hive.get() is being shared across different sessions,
    // sessionHive and Hive.get() may be different, in such case,
    // the risk of deadlock on HiveMetaStoreClient#SynchronizedHandler can happen.
    // Refresh the thread-local Hive to avoid the deadlock.
    Hive.set(sessionHive);
  }
Sets sessionHive object created based on sessionConf.
@throws HiveSQLException
service/src/java/org/apache/hive/service/cli/session/HiveSessionImpl.java