网络 弱哈希映射
Using WeakHashMap solves the problem of Thread objects not getting garbage collected, at some additional performance cost.
以一些额外的性能开销为代价,使用WeakHashMap解决了无法对Thread对象进行垃圾回收的问题。
The implementation of WeakHashMap illustrates a common idiom with weak references — that some internal object extends WeakReference.
WeakHashMap的实现展示了弱引用的一种常见用法——一些内部对象扩展WeakReference。
Switching to a WeakHashMap, as shown in Listing 2, immediately corrects the problem; the new, improved heap usage is shown in Figure 15.
切换到WeakHashMap,如清单2所示,立即更正该问题;新的改进的堆使用情况如图15所示。
When you add a mapping to a WeakHashMap, remember that it is possible that the mapping could "fall out" later because the key is garbage collected.
在向WeakHashMap中添加映射时,请记住映射可能会在以后“脱离”,因为键被垃圾收集了。
In JDK 1.2, ThreadLocal was implemented in a manner very similar to Listing 2, except that a synchronized WeakHashMap was used to store the values instead of a HashMap.
在JD k 1.2中,ThreadLocal的实现方式与清单2中的方式非常相似,除了用同步weakhashmap代替hashmap来存储values之外。