1 ThreadLocal.ThreadLocalMap的Entry继承了WeakReference< ThreadLocal > ,即ThreadLocal对象为弱引用,Entry以ThreadLocal对象的弱引用为key:
static class Entry extends WeakReference<ThreadLocal> {
/** The value associated with this ThreadLocal. */
Object value;
Entry(ThreadLocal k, Object v) {
super(k);
value = v;
}
}
2 ResourceBundle的LoaderReference继承了WeakReference< ClassLoader > ,持有一个ClassLoader对象的弱引用:
/**
* References to class loaders are weak references, so that they can be
* garbage collected when nobody else is using them. The ResourceBundle
* class has no reason to keep class loaders alive.
*/
private static class LoaderReference extends WeakReference<ClassLoader>
implements CacheKeyReference {
private CacheKey cacheKey;
LoaderReference(ClassLoader referent, ReferenceQueue<Object> q, CacheKey key) {
super(referent, q);
cacheKey = key;
}
public CacheKey getCacheKey() {
return cacheKey;
}
}