threadlocal持有的对象不能被子线程访问到。
InheritableThreadlLocal持有的对象,在子线程中会有相同的引用,也就是说子线程会复制父线程中threadlocal的引用。
private static final ThreadLocal<Map<Object, Object>> resources = new ThreadContext.InheritableThreadLocalMap();
像上面这种应用,就可以在父线程和子线程中共享变量。
threadlocal持有的对象不能被子线程访问到。
InheritableThreadlLocal持有的对象,在子线程中会有相同的引用,也就是说子线程会复制父线程中threadlocal的引用。
private static final ThreadLocal<Map<Object, Object>> resources = new ThreadContext.InheritableThreadLocalMap();
像上面这种应用,就可以在父线程和子线程中共享变量。