-
Notifications
You must be signed in to change notification settings - Fork 748
[GOBBLIN-2210] Wrap temporal heartbeat runnable #4119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,27 +28,30 @@ | |
| import java.util.concurrent.ThreadPoolExecutor; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import com.google.common.util.concurrent.ListeningScheduledExecutorService; | ||
| import org.apache.gobblin.util.executors.MDCPropagatingCallable; | ||
| import org.apache.gobblin.util.executors.MDCPropagatingRunnable; | ||
| import org.apache.gobblin.util.executors.MDCPropagatingScheduledExecutorService; | ||
| import org.slf4j.Logger; | ||
| import lombok.extern.slf4j.Slf4j; | ||
|
|
||
| import com.google.common.base.Function; | ||
| import com.google.common.base.Optional; | ||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.collect.Lists; | ||
| import com.google.common.util.concurrent.ListeningExecutorService; | ||
| import com.google.common.util.concurrent.ListeningScheduledExecutorService; | ||
| import com.google.common.util.concurrent.MoreExecutors; | ||
| import com.google.common.util.concurrent.ThreadFactoryBuilder; | ||
|
|
||
| import org.apache.gobblin.util.executors.MDCPropagatingCallable; | ||
| import org.apache.gobblin.util.executors.MDCPropagatingExecutorService; | ||
| import org.apache.gobblin.util.executors.MDCPropagatingRunnable; | ||
| import org.apache.gobblin.util.executors.MDCPropagatingScheduledExecutorService; | ||
|
|
||
|
|
||
| /** | ||
| * A utility class to use with {@link java.util.concurrent.Executors} in cases such as when creating new thread pools. | ||
| * | ||
| * @author Yinan Li | ||
| */ | ||
| @Slf4j | ||
| public class ExecutorsUtils { | ||
|
|
||
| private static final ThreadFactory DEFAULT_THREAD_FACTORY = newThreadFactory(Optional.<Logger>absent()); | ||
|
|
@@ -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()); | ||
|
||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Creates an {@link Callable<T>} which propagates the MDC | ||
| * information across thread boundaries. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.