OutOfMemoryError: Heap space and PermGen space



Solution for Tomcat Server

It’s quite common to run In memory problems when running some big Java EE application on a Tomcat server.Some of the most commmon errors are like the following ones.
This is about a full Heap space:
SEVERE: Servlet.service() for servlet jsp threw exceptionjava.lang.OutOfMemoryError: Java heap spaceThis other is about the PermGen space that’s a memory area, where compiled classes (and JSPs) are kept, and this error might happen often if the running web application have many .java and .jsp.
MemoryError: PermGen spacejava.lang.OutOfMemoryError: PermGen spaceTo increase the memory available to Tomcat, about heap and permgen the correct options are the following ones.
This sets the max heap available to Tomcat at 1Gb of memory:
--JvmMx 1024
This sets the max permgen available to Tomcat at 256Mb of memory:
Just update memory settings from a GUI frontend, or to view what happened after running the command line tool. Running the following command:
tomcat6w //ES//Tomcat6a
window will open showing all the parameters about the windows service Tomcat6.
It’s possible to see in this image that, after running the previous command, for setting higher memory limits, in the sections Maximum memory pool and at the end of the Java Options the new memory limits are set.
Memory Settings on Windows
Solution for Unix based OS(Ubuntu, Linux, Solaris..etc)
It needs to increase the memory by making changes in catalina.sh file.
Follow the following(remove any spaces from the below given line when you add to script)
steps :1) vi /usr/local/jakarta/tomcat/bin/catalina.sh
Add below given line into the catalina.sh file.
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms512m -Xmx1024m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+DisableExplicitGC"
Happy Coding

Comments (0)

Post a Comment