I want to maintain an object at the thread level or the coroutine level depending on the type of work the application is doing across different thread/coroutines. Is there a way to achieve this?
let's say for simplicity's sake, I can write a Spring Boot Application where many things are happening based on threads and only certain parts of code use coroutines to leverage their benefits. How do I maintain state based on the current execution? is there a way to do this?
Maybe my answer is a little bit late, but you can do it by either
ContinuationInterceptor
CopyableThreadContextElement
More elaborated answer with examples is provided here.
Below I will show an example for
ContinuationInterceptor
copied from those answers.and usage
output will be