Setting/Increase JVM heap size
It is possible to increase heap size allocated by the Java Virtual Machine (JVM) by using command line options.
//set initial Java heap size
-Xmx //set maximum Java heap size
-Xss //set java thread stack size
Following are few options available to change Heap Size.
Xms-Xmx
-Xss
| Java Heap | Size(MB) |
|---|---|
| Minimum Heap | 64 |
| Default | 128 |
| Maximum | 256 |
Example of Inside Heap :
public class TestMemory {
public static void main(String [] args) {
int mb = 1024*1024;
//Getting the runtime reference from system
Runtime runtime =Runtime.getRuntime();
System.out.println("##### Heap utilization statistics [MB] #####");
//Print used memory
System.out.println("Used Memory:" + (runtime.totalMemory() -
runtime.freeMemory()) / mb);
//Print free memory
System.out.println("Free Memory:" + runtime.freeMemory() / mb);
//Print total available memory
System.out.println("Total Memory:" + runtime.totalMemory() / mb);
//Print Maximum available memory
System.out.println("Max Memory:" + runtime.maxMemory() / mb);
}
}
OUTPUT



