0

My computer is Mac with 8 cores and 16G memory. I am using the functions to test how much memory I can supply to the JVM for my application.

System.out.println(Runtime.getRuntime().availableProcessors());          
System.out.println(Runtime.getRuntime().freeMemory()/(1000*1000));
System.out.println(Runtime.getRuntime().maxMemory()/(1000*1000)));
System.out.println(Runtime.getRuntime().totalMemory()/(1000*1000));

Using the default heap size, I printed out:

Available processors (cores): 8
Free memory (bytes): 915
Maximum memory (bytes): 3817
Total memory (bytes): 1955

Now in Intellij, I set JVM with -Xmx=8G

Available processors (cores): 8
Free memory (bytes): 579
Maximum memory (bytes): 7635
Total memory (bytes): 1874

The Maximum memory increased accordingly, but why didn't the 'free memory' & 'total memory' increase significantly? I need to increase the heap size for my application.

And the second question related to how to set heap size in a Spring-boot project. In the pom, I set the following:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                    <meminitial>1024m</meminitial>
                    <maxmem>6048m</maxmem>
                </configuration>
            </plugin>

I printed out the memory numbers using the same functions above in my code, the memory setting "6048m" doesn't change at all. It seems the settings have no effect. Why is that? It's a Spring-boot application.

user697911
  • 10,043
  • 25
  • 95
  • 169
  • The memory settings in the pom file are the settings of the compiler plugin, which compiles your source code. You start a Spring Boot app using `java -jar yourapp.jar`. So pass the memory options there= `java -Xmx6048m -jar yourapp.jar`. – JB Nizet Nov 03 '18 at 18:25
  • I don't start my app at a terminal by myself with the command 'java -jar ...'. It is automatically deployed at a container. I need another way to set the memory rather than the 'java ...'. Isn't POM? – user697911 Nov 03 '18 at 18:32
  • No, it isn't pom. Maven is a build tool. Read the documentation of your container to know how you can change its memory settings. – JB Nizet Nov 03 '18 at 18:34

0 Answers0