staticclassThreadLocalMap{ privatevoidset(ThreadLocal<?> key, Object value){ Entry[] tab = table; int len = tab.length; int i = key.threadLocalHashCode & (len-1);
for (Entry e = tab[i]; e != null; // 解决hash冲突 如果当前位置已经有对象,那么看下一个位置 e = tab[i = nextIndex(i, len)]) { ThreadLocal<?> k = e.get();
publicclassThreadimplementsRunnable{ /* ThreadLocal values pertaining to this thread. This map is maintained * by the ThreadLocal class. */ ThreadLocal.ThreadLocalMap threadLocals = null;
/* * InheritableThreadLocal values pertaining to this thread. This map is * maintained by the InheritableThreadLocal class. */ ThreadLocal.ThreadLocalMap inheritableThreadLocals = null; privatevoidinit(ThreadGroup g, Runnable target, String name, long stackSize, AccessControlContext acc, boolean inheritThreadLocals){ // ...... 省略其它代码 // 这里处理 InheritableThreadLocal if (inheritThreadLocals && parent.inheritableThreadLocals != null) this.inheritableThreadLocals = // 继承主线程的ThreadLocal ThreadLocal.createInheritedMap(parent.inheritableThreadLocals); // ...... 省略其它代码 } }