如何增加 JAVA 堆大小?

Hri*_*ish 8 networking java memory-usage ram network-monitoring

I need to increase the default java heap size to get OpenNMS Linkd service running smoothly, and fortunately I have 4/5 of my total installed memory free at any given time even when their is maximum load on the server. still java is not performing to it's bast. hence I need to increase the default java heap size.

Can anyone tell me how to do it?

I'm using Ubuntu 12.04 lts & total memory installed is 16 GB out of which generally 2GB to 4GB is used.

I have already checked below questions and they did not help me resolve my issue.

  1. How to increase memory allocated to java? java.lang.OutOfMemoryError: Java heap space

  2. Comparing Virtual Memory Size with Resident Size

  3. How to increase memory allocated to java? java.lang.OutOfMemoryError: Java heap space

Please feel free to edit or comment for any additional details required.

Tay*_*rez 16

You could use java -Xmx4096m in order to set your heap to 4 GB.

然后你可以export _JAVA_OPTIONS=-Xmx4096m通过他们的 (.bashrc, .zshrc) 文件添加到你的 shell 中。

  • 如果你运行`java -XshowSettings:vm`,在顶部附近应该会显示类似“Max. Heap Size (Estimated): 2.60G”的内容 (2认同)