@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; }
@Override protected WeakReference<Map<ThreadLocal<?>, Object>> initialValue() { Map<ThreadLocal<?>, Object> value = new WeakHashMap<>(); strongReferencesToThreadLocalValues.put(Thread.currentThread(), value); return new WeakReference<>(value); }