if you think this library has been useful, feel free to give any help. Don't be shy.

Click here to lend your support to: Java2word, coding for fun! and make a donation at !

Friday, August 14, 2009

java.lang.OutOfMemoryError: PermGen space, JBoss running JBoss Seam

Who has never faced to "java.lang.OutOfMemoryError: PermGen space" using JBoss Application Server and JBoss Seam Framework?

I have faced to this problem more frequently in production environment because the application has expanded considerably. I remember I had the same problem in Brazil when we were doing our final project of Post Graduate APGS at PUC University. When I got this job, the fist thing I did was change JVM settings to fix this problem in my workstation.

You are going to see in many sites and blogs people saying that increasing the PermSize will solve the problem. This way you just postpone this exception.

By default, the Collect Garbage cleans the Heap but does NOT clean the Permanent Generation.

The default value for PermSize is 64 MB which is not enough neither for development nor production environment. You definitely should not use the default configuration for professional applications involving JBoss Application Server and JBoss Seam Freamework.

The only way to really resolve this issue is enabling CG to clean the Permanent Generation space as well.

I haven't had this problem since I started using those configuration:

-Xms512m -Xmx1024m -XX:PermSize=128m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000

I run JBoss in my computer inside Eclipse but if you run outside or for production environment you have to put those parameters on the file JBOSS_HOME/bin/run.conf .

# Specify options to pass to the Java VM.
if [ "x$JAVA_OPTS" = "x" ]; then
#JAVA_OPTS="-Xms1024m -Xmx1024m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000"
JAVA_OPTS="-Xms1024m -Xmx1024m -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -XX:PermSize=192m -XX:MaxPermSize=192m -XX:+UseConcMarkSweepGC -XX:+CMSPermGenSweepingEnabled -XX:+CMSClassUnloadingEnabled"

I am sure you will never see PermGen space again!

Leonardo Pinho Correa
Java Analyst/Developer, soccer player and beer drinker


  1. Today is 14th August and I haven't had permGen neither in PRODUCTION nor in mt beautiful Mac OS!
    That is great! Problem resolved!!
    I will keep monitoring the system.
    Leonardo Pinho Correa

  2. Thank you Leonardo. We had a struggling experience in solving this problem. Your post solved our problem in our production environment.

    We have been searching for the solution for long time. Most of the websites suggest only increasing the heap size, which is not the permanant solution but just delaying the occurance of problem.

    Thanks once again....
    Java developer.

  3. In Java 6 you will see the message:

    "java Please use CMSClassUnloadingEnabled in place of CMSPermGenSweepingEnabled in the future"

    Just do what is saying and you ll be alright


  4. Hi Leonardo,
    how about docx?does java2word support that?

    1. You can give a name xxx.doc, which will still be an XML camouflaged. You can open normally on MS Word.
      java2word only generates WordProcessingML format. I may take a look at other formats in the future.

  5. Hi Leonardo,

    Can this method be applicable for Tomcat server too? Becoz, I am facing similar issues in my production environment which requires frequent restart of the application.