Use of Google-collections MapMaker?

后端 未结 2 941
走了就别回头了
走了就别回头了 2020-12-15 12:12

I just came across this answer in SO where it is mentioned that the Google-collections MapMaker is awesome.I went through the documentation but couldn\'t really figure out w

2条回答
  •  一生所求
    2020-12-15 12:45

    It may help if you look at the descriptions of SoftReference and WeakReference.

    SoftReference is very useful for use in caches, as they will be specifically cleared when memory gets low.

    WeakReference tells the Garbage Collector that it can collect the object referenced to it as long as there are no strong references to it elsewhere. This is typically used with things that can be quickly looked up again as needed.

    So, consider using MapMaker to create a ConcurrentMap with softValues for a cache, and one with weakKeys for temporary lookup tables.

    Edit: softValues uses an LRU policy.

提交回复
热议问题