How to use code that relies on ThreadLocal with Kotlin coroutines
问题 Some JVM frameworks use ThreadLocal to store the call context of a application, like the SLF4j MDC, transaction managers, security managers, and others. However, Kotlin coroutines are dispatched on different threads, so how it can be made to work? (The question is inspired by GitHub issue) 回答1: Coroutine's analog to ThreadLocal is CoroutineContext. To interoperate with ThreadLocal -using libraries you need to implement a custom ContinuationInterceptor that supports framework-specific thread