<分区>
我需要一个关于我遇到的面试问题的提示。我试图找到解决方案,但我需要这里专家的建议。如果您遇到这种特殊情况,您会采用哪些不同的策略?问题和我的想法如下:
问。您想在 java 中的列表中存储大量对象。对象的数量非常庞大并且逐渐增加,但是您的可用内存非常有限。你会怎么做?
A. I answered by saying that, once the number of elements in the list get over a certain threshold, I would dump them to a file. I would typically then build cache-like data-structure that would hold the most-frequently or recently added elements. I gave an analogy of page swapping employed by the OS.
问。但是这样会涉及到磁盘访问,会比较慢,影响执行。
我不知道这个问题的解决方案,在采访中无法正确思考。我试着回答为:
A. In this case, I would think of horizontally scaling the system or adding more RAM.
在我回答完这个问题后,我的电话采访就结束了。我觉得面试官对这个答案不满意。但是,那应该是答案。
此外,我不只是对答案感到好奇,我还想了解处理这个问题的不同方法。