Thursday, April 28, 2011

How to increase JVM Heap Size and Perm Gen space

If you are dealing with applications which have large code bases, then you might quickly run out of Java memory. Probably you might get either java.lang.OutOfMemoryError: PermGen or java.lang.OutOfMemoryError: Java heap space. In order to fix that, just having sufficient memory in your machine is not sufficient. So you need to increase the JVM Heap size and Permanent Generation space.

Setting the following environment variable before starting your application, you can increase them easily.

Unix
export JAVA_OPTS="-Xms512m -Xmx1024m -XX:MaxPermSize=1024m"

Windows
set JAVA_OPTS="-Xms512m -Xmx1024m -XX:MaxPermSize=1024m"

How to Remote Debug on Apache Tomcat

If you want to debug on your application on Apache Tomcat, then you might need to set the following environment variables and start Tomcat using the command below where 8000 is the port that you are going to connect from your IDE.

Windows
set JPDA_ADDRESS=8000
set JPDA_TRANSPORT=dt_socket

bin/catalina.bat jpda start

Unix
export JPDA_ADDRESS=8000
export JPDA_TRANSPORT=dt_socket

bin/catalina.sh jpda start