Collect uncaught RuntimeException thrown in task execution

This commit is contained in:
huanghongxun
2019-08-24 11:49:53 +08:00
parent e2787af044
commit c9b6f2f62f
3 changed files with 25 additions and 2 deletions

View File

@@ -62,6 +62,13 @@ public final class TaskExecutor {
if (!success) {
// We log exception stacktrace because some of exceptions occurred because of bugs.
Logging.LOG.log(Level.WARNING, "An exception occurred in task execution", exception);
Throwable resolvedException = resolveException(exception);
if (resolvedException instanceof RuntimeException) {
// Track uncaught RuntimeException which are thrown mostly by our mistake
if (uncaughtExceptionHandler != null)
uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), resolvedException);
}
}
taskListeners.forEach(it -> it.onStop(success, this));
@@ -253,4 +260,10 @@ public final class TaskExecutor {
}
};
}
private static Thread.UncaughtExceptionHandler uncaughtExceptionHandler = null;
public static void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler uncaughtExceptionHandler) {
TaskExecutor.uncaughtExceptionHandler = uncaughtExceptionHandler;
}
}