[英]Handling OutOfMemory Error in java
There is a global HashMap
in my application which contains custom object as a key. 我的应用程序中有一个全局
HashMap
,其中包含自定义对象作为键。 A third party will call this as API and they will create a new custom object and if it is not already there in the HashMap
they will put it into the map. 第三方将其称为API,他们将创建一个新的自定义对象,如果
HashMap
尚不存在该对象,则将其放入地图中。 How to manage the OutOfMemoryError in this case as HashMap size goes on increasing and after deployment it is tedious to increase the JVM memory. 在这种情况下,随着HashMap大小的不断增加,如何管理OutOfMemoryError,并且在部署后增加JVM内存很繁琐。
If this map can increase indefinitely, you need a different solution than just a HashMap
in memory. 如果此映射可以无限期增加,则您需要的解决方案不仅仅是内存中的
HashMap
。 Even if you keep increasing the JVM's limits, the actual hardware you're using is finite. 即使您不断增加JVM的限制,您使用的实际硬件也是有限的。
You could instead keep these keys in a database (or file, for that matter), and query against it. 相反,您可以将这些密钥保留在数据库(或文件)中,并对其进行查询。 To improve performance, you can decide to keep the N recently used keys in memory as a cache.
为了提高性能,您可以决定将N个最近使用的密钥保留在内存中作为缓存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.