从多个线程
调用weakReference.get()
方法是否安全
同时?
文档说
Once an object has been determined to be garbage collectable at that time it will atomically clear all weak references to that object
最佳答案
WeakReference.get()
由 GC 更新或 GC 线程无法更新时。否则,您可能会看到之前收集的对象。
注意:正如@Pillar 可能暗示的那样,有一个操作不是线程安全的clear()
,另一个线程可能仍然get()
调用后的值。
关于java - 同时从多个线程调用 weakReference.get() 方法是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36785864/