dmvk commented on a change in pull request #10175: [FLINK-14746][web] Handle
uncaught exceptions in HistoryServerArchive…
URL: https://github.com/apache/flink/pull/10175#discussion_r346160924
##########
File path:
flink-runtime/src/main/java/org/apache/flink/runtime/util/ScheduledFutures.java
##########
@@ -0,0 +1,58 @@
+package org.apache.flink.runtime.util;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ThreadFactory;
+import
org.apache.flink.shaded.guava18.com.google.common.util.concurrent.ThreadFactoryBuilder;
+
+/**
+ * Utils related to {@link ScheduledFuture scheduled futures}.
+ */
+public class ScheduledFutures {
+
+ private static final ThreadFactory THREAD_FACTORY = new
ThreadFactoryBuilder()
+ .setNameFormat("Flink-Scheduled-Future-SafeGuard")
+ .setDaemon(true)
+ .build();
+
+ /**
+ * Guard {@link ScheduledFuture} with scheduled future
uncaughtException handler, because
+ * {@link java.util.concurrent.ScheduledExecutorService} does not
respect the one assigned to
+ * executing {@link Thread} instance.
+ *
+ * @param scheduledFuture Scheduled future to guard.
+ * @param uncaughtExceptionHandler Handler to call in case of uncaught
exception.
+ * @param <T> Type the future returns.
+ * @return Future with handler.
+ */
+ public static <T> ScheduledFuture<T> withUncaughtExceptionHandler(
+ ScheduledFuture<T> scheduledFuture,
+ Thread.UncaughtExceptionHandler uncaughtExceptionHandler) {
+ final Thread safeguardThread = THREAD_FACTORY.newThread(() -> {
+ try {
+ scheduledFuture.get();
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
Review comment:
We need to catch it as the `Runnable` does not have `InterruptedException in
its signature`, we can replace `Thread.currentThread().interrupt();` with `//
noop` though.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services