architjainjain commented on code in PR #6501:
URL: https://github.com/apache/hive/pull/6501#discussion_r3712949372


##########
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/monitoring/yarnqueue/QueueMetricsRefreshPool.java:
##########
@@ -0,0 +1,188 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.ql.exec.tez.monitoring.yarnqueue;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Singleton manager for the JVM-wide refresh executor pool used by queue 
metrics collection.
+ * Provides a shared {@link ScheduledExecutorService} that fires periodic YARN 
RM refresh tasks
+ * across all queries in the HiveServer2 process.
+ * <p>
+ * Initialized during HiveServer2 startup via {@link #init(int)} when Tez 
session pool is set up.
+ * Pool size is configured via {@code 
hive.server2.tez.queue.metrics.refresh.threads} (default: 4).
+ * <p>
+ * All {@link YarnQueueMetricsCollector} instances share this single pool, 
ensuring efficient
+ * resource usage and preventing thread explosion when many queries run 
concurrently.
+ * <p>
+ * Thread-safe singleton implementation using double-check locking pattern.
+ */
+public final class QueueMetricsRefreshPool {
+  private static final Logger LOG = 
LoggerFactory.getLogger(QueueMetricsRefreshPool.class);
+
+  private static final int DEFAULT_THREAD_COUNT = 4;
+  public static final int JITTER_PERCENT = 10;
+
+  private static final AtomicReference<QueueMetricsRefreshPool> INSTANCE = new 
AtomicReference<>(null);

Review Comment:
   changed to volatile



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to