Increase heap size in Java

后端 未结 12 2301
情深已故
情深已故 2020-11-21 05:26

I am working on a Windows 2003 server (64-bit) with 8 GB RAM. How can I increase the heap memory maximum? I am using the -Xmx1500m flag to increase the heap siz

12条回答
  •  梦毁少年i
    2020-11-21 05:54

    You can increase the Heap Size by passing JVM parameters -Xms and -Xmx like below:

    For Jar Files:

    java -jar -Xms4096M -Xmx6144M jarFilePath.jar
    

    For Java Files:

     java -Xms4096M -Xmx6144M ClassName
    

    The above parameters increase the InitialHeapSize (-Xms) to 4GB (4096 MB) and MaxHeapSize(-Xmx) to 6GB (6144 MB).

    But, the Young Generation Heap Size will remain same and the additional HeapSize will be added to the Old Generation Heap Size. To equalize the size of Young Gen Heap and Old Gen Heap, use -XX:NewRatio=1 -XX:-UseAdaptiveSizePolicy params.

    java -jar -Xms4096M -Xmx6144M -XX:NewRatio=1 -XX:-UseAdaptiveSizePolicy pathToJarFile.jar
    

    -XX:NewRatio = Old Gen Heap Size : Young Gen HeapSize (You can play with this ratio to get your desired ratio).

提交回复
热议问题