huaxingao commented on code in PR #19100:
URL: https://github.com/apache/iceberg/pull/19100#discussion_r4684793178


##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -1979,4 +1984,34 @@ private View replace(LoadViewResponse response) {
       return new BaseView(ops, ViewUtil.fullViewName(name(), identifier));
     }
   }
+
+  /**
+   * Creates the single-threaded executor used to send metrics reports. Its 
thread exits after being
+   * idle for the given duration and does not inherit thread-locals or the 
context class loader of
+   * the thread that creates it, so a catalog that is never closed does not 
keep its users
+   * reachable.
+   */
+  @VisibleForTesting
+  static ExecutorService newMetricsExecutor(Duration idleTimeout) {
+    ThreadPoolExecutor executor =
+        new ThreadPoolExecutor(
+            1,
+            1,
+            idleTimeout.toNanos(),
+            TimeUnit.NANOSECONDS,
+            new LinkedBlockingQueue<>(),
+            new ThreadFactoryBuilder()
+                .setThreadFactory(RESTSessionCatalog::newNonInheritingThread)
+                .setDaemon(true)
+                .setNameFormat("rest-metrics-reporter-%d")
+                .build());
+    executor.allowCoreThreadTimeOut(true);
+    return executor;
+  }
+
+  private static Thread newNonInheritingThread(Runnable runnable) {
+    Thread thread = new Thread(null, runnable, "", 0, false /* 
inheritThreadLocals */);
+    thread.setContextClassLoader(RESTSessionCatalog.class.getClassLoader());

Review Comment:
   I think this is one of the main fixes. Right now no test fails if this line 
is removed. Can we add a test for it?



-- 
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