Wednesday, 24 August 2011

Java : Causes of An Out Of Memory Error (Server Si...

Manoj.Blog: Java : Causes of An Out Of Memory Error (Server Si...: Out Of Memory Error (OOME) can be solve. But what is actually it is !!!

The literal cause of an Out Of Memory Error is simple: a given To...

Java : Causes of An Out Of Memory Error (Server Side )

Out Of Memory Error (OOME) can be solve.But what is actually it is !!!



The literal cause of an Out Of Memory Error is simple: a given Tomcat instance uses up all of the heap memory allocated to it, causing an application or server crash.

Thus, the errors themselves are not particularly puzzling. The reason why OOMEs have become such a persistent topic of discussion in the Apache Tomcat community is that they are difficult to trace to their root cause.

A stack trace will not show the cause, as the problem usually lies not with Tomcat, but the web application.

Meanwhile, the 'incorrect' web app code causing Tomcat to run out of memory is usually technically correct. That is to say, in any context other than a container managed environment, the code would be considered standard. It is easy to see why a developer might have trouble determining which 'correct' section of their code was incorrect.

Here are some of the most common root causes of an OOME:

  • a simple case of the heap size being too small
  • running out of file descriptors
  • more open threads than the host OS allows
  • code with high amounts of recursion
  • code that loads a very large file into memory
  • code that retaining references to objects or classloaders
  • a large number of web apps and a small PermGen








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.............

Solution-1
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/catalina.sh or catalina.bat for how this variable is used. For example,
set CATALINA_OPTS=”-Xms512m -Xmx512m” (Windows)
In catalina.bat or catallina.sh, 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.
Solution-2
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%” -Djava.io.tmpdir=”%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...................