Wednesday, 24 August 2011

Error: error java.lang.OutOfMemoryError: PermGen space..

Error: error java.lang.OutOfMemoryError: PermGen space..

In the area of J2EE development this error is one of the prominent & frequent which is not detected by any memory tool, so its interesting to avoid .PermGen space or heap size (outof memory) error can be avoided by following solutions.............

export CATALINA_OPTS=”-Xms512m -Xmx512m” (ksh/bash)
setenv CATALINA_OPTS “-Xms512m -Xmx512m” (tcsh/csh)

Stop Tomcat server, set environment variable CATALINA_OPTS, and then restart Tomcat. Look at the file tomcat-install/bin/ or catalina.bat for how this variable is used. For example,
set CATALINA_OPTS=”-Xms512m -Xmx512m” (Windows)
In catalina.bat or, you may have noticed CATALINA_OPTS, JAVA_OPTS, or both can be used to specify Tomcat JVM options. What is the difference between CATALINA_OPTS and JAVA_OPTS? The name CATALINA_OPTS is specific for Tomcat servlet container, whereas JAVA_OPTS may be used by other java applications (e.g., JBoss). Since environment variables are shared by all applications, we don’t want Tomcat to inadvertently pick up the JVM options intended for other apps. I prefer to use CATALINA_OPTS.
Change the Catalina.bat file in Tomcat/bin with following code.
Edit catalina.bat.If you do not have catalina.bat , contact me.
If you have the .bat file, open and search for CATALINA_OPTS
If the parameter is set to no value, set it to -Xms256m -Xmx512m -XX:MaxPermSize=256m and move it to the top of the file.
If the above doesn’t work revoke the changes did in the previous step, go to the last lines of the catalina.bat. Look out for %_EXECJAVA% %JAVA_OPTS%. It will be in a few lines.
Insert the parameter in those lines. Like the one below.
%_EXECJAVA% %JAVA_OPTS% -Xms256m -Xmx512m -XX:MaxPermSize=256m %DEBUG_OPTS% -Djava.endorsed.dirs=”%JAVA_ENDORSED_DIRS%” -classpath “%CLASSPATH%” -Dcatalina.base=”%CATALINA_BASE%” -Dcatalina.home=”%CATALINA_HOME%””%CATALINA_TMPDIR%” %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
Here i have removed %CATALINA_OPTS% from them, to avoid setting parameters more than once.

It will really help you.I was in trouble with my team mates.
But now you can Enjoy...................