how to increase java heap memory permanently?

前端 未结 5 1741
南笙
南笙 2020-12-02 23:14

I have one problem with java heap memory. I developed one client server application in java which is run as a windows service it requires more than 512MB of memory. I have 2

5条回答
  •  囚心锁ツ
    2020-12-03 00:18

    The Java Virtual Machine takes two command line arguments which set the initial and maximum heap sizes: -Xms and -Xmx. You can add a system environment variable named _JAVA_OPTIONS, and set the heap size values there.
    For example if you want a 512Mb initial and 1024Mb maximum heap size you could use:

    under Windows:

    SET _JAVA_OPTIONS = -Xms512m -Xmx1024m
    

    under Linux:

    export _JAVA_OPTIONS="-Xms512m -Xmx1024m"
    

    It is possible to read the default JVM heap size programmatically by using totalMemory() method of Runtime class. Use following code to read JVM heap size.

    public class GetHeapSize {
        public static void main(String[]args){
    
            //Get the jvm heap size.
            long heapSize = Runtime.getRuntime().totalMemory();
    
            //Print the jvm heap size.
            System.out.println("Heap Size = " + heapSize);
        }
    }
    

提交回复
热议问题