From 348cf0f3433f654a68e82a9502b30739fc144f40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20D=C3=BCmont?= <22489773+newtork@users.noreply.github.com> Date: Thu, 3 Jul 2025 12:39:24 +0200 Subject: [PATCH] Update thread-context.mdx --- .../features/multi-tenancy/thread-context.mdx | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) 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