Package org.springframework.core.task.support

# Class ContextPropagatingTaskDecorator

java.lang.Object
org.springframework.core.task.support.ContextPropagatingTaskDecorator

All Implemented Interfaces:
  `TaskDecorator`

public class ContextPropagatingTaskDecorator extends Object implements 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:
  - `CompositeTaskDecorator`

## Constructor Summary

Constructors
Constructor
Description
`ContextPropagatingTaskDecorator()`
Create a new decorator that uses a default instance of the `ContextSnapshotFactory`.
`ContextPropagatingTaskDecorator(io.micrometer.context.ContextSnapshotFactory factory)`
Create a new decorator using the given `ContextSnapshotFactory`.

## Method Summary

Modifier and Type
Method
Description
`Runnable`
`decorate(Runnable runnable)`
Decorate the given `Runnable`, returning a potentially wrapped `Runnable` for actual execution, internally delegating to the original `Runnable.run()` implementation.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ContextPropagatingTaskDecorator

public ContextPropagatingTaskDecorator()
Create a new decorator that uses a default instance of the `ContextSnapshotFactory`.

### ContextPropagatingTaskDecorator

public ContextPropagatingTaskDecorator(io.micrometer.context.ContextSnapshotFactory factory)
Create a new decorator using the given `ContextSnapshotFactory`.

Parameters:
  `factory` - the context snapshot factory to use.

## Method Details

### decorate

public Runnable decorate(Runnable runnable)
Description copied from interface: `TaskDecorator`
Decorate the given `Runnable`, returning a potentially wrapped `Runnable` for actual execution, internally delegating to the original `Runnable.run()` implementation.

Specified by:
  `decorate` in interface `TaskDecorator`
Parameters:
  `runnable` - the original `Runnable`
Returns:
  the decorated `Runnable`