https://blog.csdn.net/a837199685/article/details/52712547
package com.cn.xiaonuo.main.test.module; import com.cn.xiaonuo.core.tenant.entity.TenantInfo; public class TenantTest { public static void main(String[] args) { //变量 TenantInfo tenantInfo = new TenantInfo(); tenantInfo.setCode("shibei"); //变量可父子线程传递 InheritableThreadLocal<TenantInfo> t1 = new InheritableThreadLocal<>(); t1.set(tenantInfo); //变量无法父子线程传递 ThreadLocal<TenantInfo> t2 = new ThreadLocal<>(); t2.set(tenantInfo); new Thread(() -> { System.out.println(t1.get()); System.out.println(t2.get()); }).start(); } }