Package org.hawaiiframework.async
Class AbortableTaskDecorator
java.lang.Object
org.hawaiiframework.async.AbortableTaskDecorator
- All Implemented Interfaces:
org.springframework.core.task.TaskDecorator
public class AbortableTaskDecorator
extends Object
implements org.springframework.core.task.TaskDecorator
Task decorator to copy the MDC from the calling thread to the executing thread..
- Since:
- 2.0.0
-
Constructor Summary
ConstructorsConstructorDescriptionAbortableTaskDecorator(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor taskExecutor, ScheduledThreadPoolExecutor timeoutExecutor) Construct an instance. -
Method Summary
-
Constructor Details
-
AbortableTaskDecorator
public AbortableTaskDecorator(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor taskExecutor, ScheduledThreadPoolExecutor timeoutExecutor) Construct an instance.- Parameters:
taskExecutor- The executor that will execute the runnable we're decorating.timeoutExecutor- The executor aborts tasks that have timed-out.
-
-
Method Details
-
decorate
We create a new
AbortableTaskRunnablethat holds the current thread's MDC. This is for logging purposes, so that logging within therunnableis done with the correct logging context. For instance, the transaction id is logged and the current user etc.Next to this, we create an schedule a
TimeoutGuardTask. This task will stop the runnable we're decorating if the configured timeout has lapsed.The
AbortableTaskRunnablewill stop the execution of theTimeoutGuardTaskafter it completes.- Specified by:
decoratein interfaceorg.springframework.core.task.TaskDecorator- Parameters:
runnable- The runnable to decorate.- Returns:
- a decorated runnable.
-