svalaskevicius commented on code in PR #15312:
URL: https://github.com/apache/iceberg/pull/15312#discussion_r2891045175
##########
core/src/main/java/org/apache/iceberg/util/ThreadPools.java:
##########
@@ -149,8 +152,86 @@ public static ExecutorService newWorkerPool(String
namePrefix, int poolSize) {
* that should be automatically cleaned up on JVM shutdown.
*/
public static ExecutorService newExitingWorkerPool(String namePrefix, int
poolSize) {
- return MoreExecutors.getExitingExecutorService(
- (ThreadPoolExecutor) newFixedThreadPool(namePrefix, poolSize));
+ ExecutorService service =
+ Executors.unconfigurableExecutorService(newFixedThreadPool(namePrefix,
poolSize));
+ THREAD_POOL_MANAGER.addThreadPool(service, DEFAULT_SHUTDOWN_TIMEOUT);
+ return service;
+ }
+
+ /**
+ * Force manual shutdown of the thread pools created via the {@link
#newExitingWorkerPool(String,
+ * int)}.
+ *
+ * <p>This method allows: (1) to stop thread pools manually, to avoid leaks
in hot-reload
+ * environments; (2) opt-out of the standard shutdown mechanism to manage
graceful service stops
+ * (and commit the last pending files, if the client application needs to
react to shutdown hooks
+ * on its own).
+ *
+ * <p>Please only call this method at the end of the intended usage of the
library, and NEVER
+ * before, as this method will stop thread pools required for normal library
workflows.
+ */
+ public static void shutdownThreadPools() {
+ THREAD_POOL_MANAGER.shutdownAll();
+ removeShutdownHook();
+ }
+
+ /**
+ * Initialize a shutdown hook to stop the thread pools created via the {@link
+ * #newExitingWorkerPool(String, int)}.
+ */
+ @SuppressWarnings("ShutdownHook")
+ static synchronized void initShutdownHook() {
Review Comment:
this is used in tests - so that they could access it to test.. do you have
alternative recommendation?
--
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]