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(

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 or catalina.bat file.

How to fix it?

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

2) Assign following line to JAVA_OPTS variable and add it into 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 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: 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.
case "`uname`" in
CYGWIN*) cygwin=true;;
OS400*) os400=true;;
Darwin*) darwin=true;;

# resolve links - $0 may be a softlink

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?

  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.

  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

  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.

  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.

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

  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

  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 ETH 316 Week 5 Individual Assignment provider

  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

  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 ETH 316 Final provider

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

  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

  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

  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

  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… MGT 521 provider

  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.

  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.

  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.

  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

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

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

  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.