How to convince Java Garbage Collector to run when working set is small?

后端 未结 4 1205
北海茫月
北海茫月 2021-02-01 18:32

This is yet another \"please tell me how to force the Java garbage collector to run\" question. In our application, I believe we have good reasons for doing this.

This i

4条回答
  •  温柔的废话
    2021-02-01 19:02

    I found that java GC deals very poorly with a large number of objects (20-100m objects). your situation would have been worse if those objects would actually had remain alive, because GC would be horrible even if there was nothing to actually collect.

    the solution is to reduce the number of objects (not the total memory you are using). I would dare to guess that you analysis phase is using collections and many primitive wrappers (Integer, Long etc). if this is the case, one solution is to switch to a primitive collections library. one such library is what I created to solve a similar problem I encountered where I ran a simulation with 100m live objects for a long time. That library is called Banana, see the wiki for details.

提交回复
热议问题