diff --git a/docs-java/features/multi-tenancy/thread-context.mdx b/docs-java/features/multi-tenancy/thread-context.mdx index b8a84b0fd7d..e3e68f7603a 100644 --- a/docs-java/features/multi-tenancy/thread-context.mdx +++ b/docs-java/features/multi-tenancy/thread-context.mdx @@ -121,8 +121,9 @@ public class AsynchronousConfiguration implements AsyncConfigurer { You can read more about the `@Async` functionality [here](https://www.baeldung.com/spring-async). -:::tip Security Context -The Spring `SecurityContext` can be propagated to `@Async` calls. +
+ The Spring SecurityContext can be propagated to @Async calls. + Replace the above executor with this one: ```java @@ -138,7 +139,32 @@ And add this dependency: ``` -::: +
+ +
+ The Spring TaskDecorator instances can be invoked when migrating ThreadContext. + +Let's assume you have a `CustomTaskDecorator` that implements Springs `TaskDecorator` API. +You want to invoke an `ResultT customOperation()` via the `ResilienceDecorator` API. +This internally requires handling of additional threads and their contexts. +You can use the `AtomicReference` container to store information between threads. + +```java +@Autowired +CustomTaskDecorator decorator; + +// ... + +AtomicReference result = new AtomicReference<>(); +Runnable decorated = decorator.decorate(() -> result.set(customOperation())); + +ResultT resilientResult = ResilienceDecorator.executeSupplier(() -> { + decorated.run(); + return result.get(); +}, customResilienceConfiguration); +``` + +
### Passing on Other ThreadLocals