Java class member scope
See the following figure for the JAVA class member scope:
- Java virtual machine-level scopes are shared across Java virtual machines by prefixing class member variables with the static keyword.
- Class A, Class B, and Class C member variables are shared only among Class instances. Class A, Class B, and Class C member variables are shared only among Class instances.
- In addition to member variable sharing at the above level, thread-level variable sharing is needed when calling chain tracing to recognize that the invocation of multiple class instances at different levels is the same request, and the invocation of this request is completed in an independent thread.
Implement thread variable sharing
Thread variable sharing is possible in Java with ThreadLocal, and even if you don’t need to trace the call chain, it’s useful to just track the data flow of SQL calls.
The use of ThreadLocal can refer to this article: www.jianshu.com/p/4e1fcdfb6… end.
Wechat Official Account:
Join “Java Stack actual combat camp” knowledge planet, participate in the discussion, more actual combat code to share!
t.zsxq.com/RNzfi2j