Setting/Increase JVM heap size
It is possible to increase heap size allocated by the Java Virtual Machine (JVM) by using command line options.Following are few options available to change Heap Size.
- -Xms<size> set initial Java heap size
- -Xmx<size> set maximum Java heap size
- -Xss<size> set java thread stack size
- java -Xms64m -Xmx256m HelloWorld
Getting / Reading default heap size
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); |
} |
} |