Is there java.util.concurrent equivalent for WeakHashMap?

前端 未结 6 1147
轻奢々
轻奢々 2020-12-08 13:38

Can the following piece of code be rewritten w/o using Collections.synchronizedMap() yet maintaining correctness at concurrency?

Collections.sy         


        
6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 13:56

    Does wrapping the WeakHashMap in a synchronized map still work correctly for what you want to do, since the garbage collector can modify the weakreferences directly at anytime, bypassing the synchronized map wrapper? I think WeakHashMap only truly works in a single threaded model.

提交回复
热议问题