@Override
            public TezSessionPoolSession create(TezSessionPoolSession oldSession) {
              if (oldSession != null) {
                return createAndInitSession(
                    oldSession.getQueueName(), oldSession.isDefault(), oldSession.getConf());
              }
              // We never resize the pool, so assume this is initialization.
              // If that changes, we might have to make the factory interface more complicated.
              /*
               * In a single-threaded init case, with this the ordering of sessions in the queue will be
               * (with 2 sessions 3 queues) s1q1, s1q2, s1q3, s2q1, s2q2, s2q3 there by ensuring uniform
               * distribution of the sessions across queues at least to begin with. Then as sessions get
               * freed up, the list may change this ordering.
               * In a multi threaded init case it's a free for all.
               */
              int localQueueIx;
              synchronized (defaultQueueList) {
                localQueueIx = queueIx;
                ++queueIx;
                if (queueIx == defaultQueueList.length) {
                  queueIx = 0;
                }
              }
              HiveConf sessionConf = new HiveConf(initConf);
              return createAndInitSession(defaultQueueList[localQueueIx], true, sessionConf);
          }
Note: this is not thread-safe.
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/TezSessionPoolManager.java