Today, looking at the code of the open source project, I saw why a class called TransmittableThreadLocal put the object set into it!

Today, looking at the code of the open source project, I saw why a class called TransmittableThreadLocal put the object set in!
what is the purpose of this class? In what scenarios will
be used? What are the benefits of
?

Mar.24,2021

TransmittableThreadLocal this class is from an open source project of Ali: https://github.com/alibaba/tr.. The reason why this class appears is to solve the problem that when using cached thread components such as thread pool and Tomcat, such as ThreadPoolExecutor and tomcat thread pool, the data and ThreadLocal in one thread will be reused by the next Runable class or Http request without deletion or unbinding. When submitting a task to the thread pool, TransmittableThreadLocal submits the ThreadLocal data together when submitting the task to the thread pool to solve this problem, which is equivalent to re-set the ThreadLocal.

Menu