Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetty 7: OutOfMemoryError: PermGen space on application redeploy

First time app starts correctly. Then I delete webapp/*.war file and paste new version of *.war. Jetty start deploying new war but error java.lang.OutOfMemoryError: PermGen space occurs. How can I configure Jetty to fix error / make correct redeploy?

This solution doesn't help me.
Jetty version: jetty-7.4.3.v20110701

like image 897
fedor.belov Avatar asked Aug 05 '11 12:08

fedor.belov


2 Answers

There is probably no way to configure the problem away. Each JVM has one PermGen memory area that is used for class loading and static data. Whenever your application gets undeployed its classloader should be discarded and all classes loaded by it as well. When this fails because other references to the classloader still exist, garbage collecting the classloader and your applications classes will also fail.

A blog entry and its follow up explain a possible source of the problem. Whenever the application container's code uses a class that holds a reference to one of your classes, garbage collection of your classes is prevented. The example from the mentioned blog entry is the java.util.logging.Level constructor:

protected Level(String name, int value) {
    this.name = name;
    this.value = value;
    synchronized (Level.class) {
        known.add(this);
    }
}

Note that known is a static member of java.util.logging.Level. The constructor stores a reference to all created instances. So as soon as the Level class was loaded or instantiated from outwith your application's code, garbage collection can't remove your classes.

To solve the problem you could avoid all classes that are in use outwith your own code or ensure no references are held to your classes from outwith your code. Both problems could occur within any class delivered with Java and are thus not feasible to be fixed within your application. You cannot prevent the problem by altering only your own code!

Your options are basically:

  • Increasing the memory limits and have the error strike less often
  • Analyze your code as detailed in the linked blog posts and avoid using the classes that store references to your objects
like image 61
Augustus Kling Avatar answered Oct 26 '22 23:10

Augustus Kling


If a PermGen out of memory occurs, you need to restart the jvm, in your case restart jetty. You may increase the PermGen space with the JVM options in your linked solution so this happens later (with later I mean: after more redeploys). But it will happen every once in a while and you can do next to nothing to avoid that. The answer you linked explained well what PermGenSpace is and why it overflows.

Use:

-XX:PermSize=64M -XX:MaxPermSize=128M

or, if that was not enough yet

-XX:PermSize=256M -XX:MaxPermSize=512M

Also, be sure to increase the amount of space available to the vm in general if you use this commands.

use

-Xms128M -Xmx256M
like image 39
Angelo Fuchs Avatar answered Oct 27 '22 01:10

Angelo Fuchs