Jetty 7: OutOfMemoryError: PermGen space on application redeploy

不问归期 提交于 2020-01-01 03:24:08

问题


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


回答1:


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



回答2:


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



回答3:


For Jetty 7.6.6 or later this may help http://www.eclipse.org/jetty/documentation/current/preventing-memory-leaks.html.

We used the AppContextLeakPreventer and it helped with the OOM errors due to permgen space




回答4:


I have this same problem with HotSpot, but with JRockit, which doesn't have a Permanent Generation, the problem has gone away. It's free now, so you might want to try it: https://blogs.oracle.com/henrik/entry/jrockit_is_now_free_and




回答5:


Looks very much like Permanent Generation leak. Whenever your application left some classes to hang around after it is undeployed, you get this problem. You can try the latest version of Plumbr, may be it will find the left-over classes.




回答6:


For Readers of the Future (relative to when this question has been asked):

In JDK 8 the Perm Gen Space is gone (not there anymore). Instead there is now Metaspace which is taken from the native space of the machine.

If you had problems of Perm Gen Overflow then you might want to have a look into this explanation and this comments on the removal process.



来源:https://stackoverflow.com/questions/6956613/jetty-7-outofmemoryerror-permgen-space-on-application-redeploy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!