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.