Java 类java.lang.ThreadLocal 实例源码

项目:ImprovedThreadLocal    文件:ImprovedThreadLocal.java   
@SuppressWarnings("unchecked")
@Override
public T get() {
    Map<ThreadLocal<?>, Object> threadLocalMap = threadLocalWeakReferenceToMapOfThreadLocals.get().get();
    T value = (T) threadLocalMap.get(this);
    if (value == null && !threadLocalMap.containsKey(this)) {
        value = this.initialValue();
        set(value);
    }
    return value;
}
项目:ImprovedThreadLocal    文件:ImprovedThreadLocal.java   
@Override
protected WeakReference<Map<ThreadLocal<?>, Object>> initialValue() {
    Map<ThreadLocal<?>, Object> value = new WeakHashMap<>();
    strongReferencesToThreadLocalValues.put(Thread.currentThread(), value);
    return new WeakReference<>(value);
}