Class ContextPropagatingTaskDecorator
java.lang.Object
org.springframework.core.task.support.ContextPropagatingTaskDecorator
- All Implemented Interfaces:
TaskDecorator
TaskDecorator
that wraps the execution
of tasks, assisting with context propagation.
This operation is only useful when the task execution is scheduled on a different
thread than the original call stack; this depends on the choice of
TaskExecutor
. This is particularly useful for
restoring a logging context or an observation context for the task execution. Note that
this decorator will cause some overhead for task execution and is not recommended for
applications that run lots of very small tasks.
- Since:
- 6.1
- Author:
- Brian Clozel
- See Also:
-
Constructor Summary
ConstructorDescriptionCreate a new decorator that uses a default instance of theContextSnapshotFactory
.ContextPropagatingTaskDecorator
(io.micrometer.context.ContextSnapshotFactory factory) Create a new decorator using the givenContextSnapshotFactory
. -
Method Summary
Modifier and TypeMethodDescriptionDecorate the givenRunnable
, returning a potentially wrappedRunnable
for actual execution, internally delegating to the originalRunnable.run()
implementation.
-
Constructor Details
-
ContextPropagatingTaskDecorator
public ContextPropagatingTaskDecorator()Create a new decorator that uses a default instance of theContextSnapshotFactory
. -
ContextPropagatingTaskDecorator
public ContextPropagatingTaskDecorator(io.micrometer.context.ContextSnapshotFactory factory) Create a new decorator using the givenContextSnapshotFactory
.- Parameters:
factory
- the context snapshot factory to use.
-
-
Method Details
-
decorate
Description copied from interface:TaskDecorator
Decorate the givenRunnable
, returning a potentially wrappedRunnable
for actual execution, internally delegating to the originalRunnable.run()
implementation.- Specified by:
decorate
in interfaceTaskDecorator
- Parameters:
runnable
- the originalRunnable
- Returns:
- the decorated
Runnable
-