giovedì 13 gennaio 2011

Preventing Tomcat java.lang.OutOfMemoryError: PermGen space failure


The "OutOfMemoryError: PermGen space" message is normally encountered during development activites where a long-running JVM is asked to load/unload builds. However it can also be encountered in a recently spawned JVM under the "right" set of conditions.

The message is a symptom of an incomplete garbage collection sweep where resources are not properly released upon unload/restart.

Tomcat production server sometime will hit the following java.lang.OutOfMemoryError: PermGen space error.

java.lang.OutOfMemoryError: PermGen space
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)

It’s usually happened when the Tomcat start and stop few times. It’s just funny, however you can fine tune it with some minor changes in the Tomcat configuration setting. By default, Tomcat assigned very little memory for the running process, you should increase the memory by make change in catalina.sh or catalina.bat file.

How to fix it?

1) Find where is Cataline.sh located. We need to make some changes in "catalina.sh" file.
P.S Cataline.sh is located at \tomcat folder \bin\catalina.sh

2) Assign following line to JAVA_OPTS variable and add it into catalina.sh file.
JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8
-server -Xms1536m -Xmx1536m
-XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"

Partial example of the catalina.sh file
# JSSE_HOME (Optional) May point at your Java Secure Sockets Extension
# (JSSE) installation, whose JAR files will be added to the
# system class path used to start Tomcat.
#
# CATALINA_PID (Optional) Path of the file which should contains the pid
# of catalina startup java process, when start (fork) is used
#
# $Id: catalina.sh 609438 2008-01-06 22:14:28Z markt $
# -----------------------------------------------------------------------------

JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m
-Xmx1536m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m
-XX:MaxPermSize=256m -XX:+DisableExplicitGC"


# OS specific support. $var _must_ be set to either true or false.
cygwin=false
os400=false
darwin=false
case "`uname`" in
CYGWIN*) cygwin=true;;
OS400*) os400=true;;
Darwin*) darwin=true;;
esac

# resolve links - $0 may be a softlink
PRG="$0"

3) Done. Restart Tomcat.
You should change the “Xms” and “PermSize” value base on your server capability.

22 commenti:

  1. Have you checked out memory leaks in your app?
    http://blogs.oracle.com/fkieviet/entry/classloader_leaks_the_dreaded_java

    RispondiElimina
  2. Nice tutorial, people often don't differentiate between OOOM in Heap and OOOM in Perm Gen, even though both are completely different and require different approach to solve. I come to know when I got this error on tomcat and see 2 ways to solve java.lang.OutOfMemoryError:Perm Gen Space in Java article, quite useful for me.

    RispondiElimina
  3. Virtual hosting is a method for hosting multiple domain names on a computer using a single IP address.
    Virtual assistant Alberta
    Virtual Business Solution Canada

    RispondiElimina
  4. I am very much pleased with the contents you have mentioned. It contains truly information. I want to thank you for this informative read; I really appreciate for sharing this great post....... by OPS 571 Final Exam provider.

    RispondiElimina
  5. I blog quite often and I truly thank you for your information. This article has truly peaked my interest. I will book mark your site and keep checking for new information about once a week.. ..... by BIS 220 Week 5 provider.

    RispondiElimina
  6. Great!! well-created email with obvious and immediate information and information. Simple and sweet and useful! goodJob!
    MGT 311 Week 2 Individual Assignment

    RispondiElimina
  7. I just study through the whole product of yours and it was rather outstanding. This is a large article thanks for circulating this useful information. I will check out your website regularly for some newest post. by MGT 311 Final Exam

    RispondiElimina
  8. I would like read more information about this, is very interesting! Thanks for the information. A worth bookmarking blog. I would be reading your articles regularly from now on.by ETH 316 Week 5 Individual Assignment provider

    RispondiElimina
  9. Great content i would be glad if you still post these type of Articles so that i can gain lot of information.For more information please go through
    MGT 498 Week 4

    RispondiElimina
  10. I blog absolutely generally and I absolutely acknowledge you for your information. This commodity has absolutely ailing my interest. I will book mark your armpit and accumulate blockage for fresh advice about already a week.by ETH 316 Final provider



    RispondiElimina
  11. Awesome Blog!! That was wonderful. Your thought-about process is marvellous. The way you tell the factor is amazing. you're extremely a master.by LDR 531 Week 3 Assignment

    RispondiElimina
  12. The first thing is that you have to plan your time. It means that you have to share your study load on all of the months of the semester. When doing so you have already acquired the required knowledge before the exam day approaches....for more information you can also go through
    MGT 498

    RispondiElimina
  13. I am actual abundant admiring with the capacity you accept mentioned. It contains absolutely information. I appetite to acknowledge you for this advisory read; I absolutely acknowledge for administration this abundant post..

    by ETH 316 Week 3 Idividual Assignment provider

    RispondiElimina
  14. I aloof abstraction through the accomplished artefact of castigation and it was rather outstanding. This is a ample commodity acknowledgment for circulating this advantageous information. I will analysis out your website consistently for some newest post... by ETH 316 Week 5 Idividual Assignment provider

    RispondiElimina
  15. I am actual blessed back apprehend this blog column because blog column accounting in acceptable address and address on acceptable topic. Thanks for administration admired information…....by MGT 521 provider


    RispondiElimina
  16. Great agreeable i would be animated if you still column these blazon of Articles so that i can accretion lot of information.For added advice amuse go through by
    MGT 420 Week 2 provider.

    RispondiElimina
  17. This is the first time i am reading your post and admire that you posted article which gives users lot of information regarding particular topic thanks for this share.I am impressed with the content you provided....... by ECO 365 Final Exam provider.

    RispondiElimina
  18. I am very much satisfied with the material you have described. I experienced every little bit aspect of it. It contains truly details. I want to thank you for this useful read; I really appreciate for discussing this excellent publish....... by LAW 421 Final Exam provider.

    RispondiElimina
  19. Thank you so much for providing this valuable information. It is very important to us. You Posted a Good Stuff... by MGT 521 provider


    RispondiElimina
  20. Really Admire the information.. Thanks you. LAW 421 Week 5

    RispondiElimina
  21. This is extremely helpful info!! Very good work. Everything is very interesting to learn and easy to understood. Thank you for giving information.
    Signature:
    Jugar juegos de frozen en línea gratis, los nuevos de princesa de Disney juegos frozen - la princesa encantadora y linda. Divertirse frozen!

    RispondiElimina
  22. I faced error like java.lang.OutOfMemoryError i found your post in looking for solution its help me in my Apache tomcat online training thank you.

    RispondiElimina