Thursday 21 January 2016

Java memory structure

1. Java Heap Size:
Heap memory area is used to store objects created by your Java application and Garbage Collection uses this to free memory area used by Java Objects that are not in used.
For a heavy Java process, insufficient Heap size will cause java.lang.OutOfMemoryError Java heap space exception.

Command to increase Heap Size
-Xms<size> - Set initial Java heap size
-Xmx<size> - Set maximum Java heap size

$ java -Xms512m -Xmx1024m AppName


2. Perm Gen Size
Perm Gen memory area is used to store class definition and metadata of loaded classes. If a large code base project is loaded, the insufficient Perm Gen Size will cause the Java.Lang.OutOfMemoryError: PermGen exception.

Command to increate Perm Gen Size
-XX:PermSize=<Size> - Set initial perm size
-XX:MaxPerSize=<size>  - Set Maximum Per Size
Example:
$ java -XX:PermSize=64m -XX:MaxPermSize=128m AppName


3. Java Stack Size
Stack Size memory area is used to define the size of thread. If any application have many thread it recomended to reduce the stack size to avoid Java.Lang.OutOfMemoryError exception

Command to increase Stack Size
-Xss<size> - Set Java thread stack size
Example:
-Xss512k

No comments:

Post a Comment