thisisArjit commented on code in PR #4119: URL: https://github.com/apache/gobblin/pull/4119#discussion_r2234728408
########## gobblin-utility/src/main/java/org/apache/gobblin/util/ExecutorsUtils.java: ########## @@ -162,6 +165,27 @@ public static Runnable loggingDecorator(Runnable runnable) { return new MDCPropagatingRunnable(runnable); } + + /** + * Wraps a {@link Runnable} task with exception handling to ensure that + * any thrown exception does not terminate the thread or scheduled executor. + * This is useful for long-running or recurring tasks where resilience is critical. + * + * @param runnable the task to wrap + * @return a safe {@link Runnable} that logs and suppresses exceptions + */ + public static Runnable safeRunnable(Runnable runnable) { + return () -> { + try { + runnable.run(); + } catch (Exception exception) { + // Catch all exceptions to prevent the thread from dying + // and log the exception + log.error("Caught exception in runnable {}", exception.getMessage()); Review Comment: should we log stacktrace? -- 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: dev-unsubscr...@gobblin.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org