Forcing deallocation of large cache object in Java

后端 未结 7 1002
醉梦人生
醉梦人生 2021-02-04 09:36

I use a large (millions) entries hashmap to cache values needed by an algorithm, the key is a combination of two objects as a long. Since it grows continuously (because keys in

7条回答
  •  花落未央
    2021-02-04 10:15

    Instead of using a HashMap or other map implementation as a cache you could try to use a framework specialized in caching. A well known caching framework for Java is Ehcache.

    Caching frameworks let you usually configure expiration policies based on time (e.g. time to live, time to idle) or usage (e.g. least frequently used, least recently used), some may even allow you to specify a maximum amount of memory usage.

提交回复
热议问题