首先来看一下线程安全问题产生的两个前提条件: 1.数据共享,多个线程访问同样的数据。 2.共享数据是可变的,多个线程对访问的共享数据作出了修改。 实例: 定义一个共享数据: public static int a 0; 多线程对该共享…
前言 Briefly, a thread’s “probe” value is a non-zero hash code that (probably) does not collide with other existing threads with respect to any power of two collision space. When it does collide, it is pseudo-randomly adjusted (using a Marsaglia XorShif…
holder 变量是一个InheritableThreadLocal, 他是一个map但是一直都是当作Set在用,value一直是空 The value of holder is type WeakHashMap<TransmittableThreadLocal, ?>, but it is used as Set (aka. do NOT use about value, always null). 每次使用hold…
概念:
ThreadLocal的概念:摘自ThreaLocal的注释
This class provides thread-local variables. These variables differ from* their normal counterparts in that each thread that accesses one (via its* {code get} or {code set} method) has it…
public class UserContextTest {Testpublic void test() {// UserContext可以参考Dubbo的RpcContext;RpcContext中使用的InternalThreadLocalMap找到Entry的方式是数组索引,比JDK的线性探测方式性能强new Thread(() -> {UserInfo userInfo new UserI…