Grails PermGem error

。_饼干妹妹 提交于 2019-11-30 14:30:56

问题


I need help with this problem. I need someone to explain to me why is this happening and how to prevent or avoid it.

Exception in thread "Thread-747" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-748" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-759" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-760" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-764" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-765" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-766" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-767" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-773" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-774" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-780" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-781" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-788" java.lang.OutOfMemoryError: PermGen space
Exception in thread "Thread-789" java.lang.OutOfMemoryError: PermGen space
2011-06-20 14:42:10,668 [http-8080-6] ERROR [/CM].[grails]  - Servlet.service() for servlet grails threw exception
java.lang.OutOfMemoryError: PermGen space
2011-06-20 14:42:10,668 [http-8080-6] ERROR [/CM].[default]  - Servlet.service() for servlet default threw exception
java.lang.OutOfMemoryError: PermGen space
: java.lang.OutOfMemoryError: PermGen space
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:116)
        at _GrailsPackage_groovy$_run_closure8.doCall(_GrailsPackage_groovy:275)
        at _GrailsPackage_groovy$_run_closure8.call(_GrailsPackage_groovy)
        at _GrailsRun_groovy$_run_closure8.doCall(_GrailsRun_groovy:245)
        at RunApp$_run_closure1.doCall(RunApp.groovy:35)
        at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
        at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
        at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
        at gant.Gant.withBuildListeners(Gant.groovy:427)
        at gant.Gant.this$2$withBuildListeners(Gant.groovy)
        at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
        at gant.Gant.dispatch(Gant.groovy:415)
        at gant.Gant.this$2$dispatch(Gant.groovy)
        at gant.Gant.invokeMethod(Gant.groovy)
        at gant.Gant.executeTargets(Gant.groovy:590)
        at gant.Gant.executeTargets(Gant.groovy:589)
Caused by: java.lang.OutOfMemoryError: PermGen space
--- Nested Exception ---
java.lang.OutOfMemoryError: PermGen space
Error automatically restarting container: java.lang.OutOfMemoryError: PermGen space
Error executing script RunApp: PermGen space
java.lang.OutOfMemoryError: PermGen space
Error executing script RunApp: PermGen space
Application context shutting down...
Application context shutdown.

回答1:


The PermGen is a region of your JVM's memory that is used to load classes.

As you application executes, it uses more and more of this memory, especially if you are in a debugging environment, of if you make extensive use of closures.

The way to fix this is to add more of it!

This is done by passing one or two parameters to the JVM when launching your application.

The parameters are :

-XX:MaxPermSize=256m
-XX:PermSize=128m

(adjust the values to your specific needs)

The PermSize will be the initial size of the PermGen, and the MaxPermSize will be the maximum size at which it will increase before throwing you an exception like in your post.

By default, it is set to 64M, which is not much if you have a 'real' application.

PAY ATTENTION : Your total memory usage will be:Heap size + Perm Size




回答2:


If you are using Servlet Version 3.0 then even increasing your memory won't be of any help since it's a problem with the groovy compiler. The new version 1.8.2/1.9 (?) which will be released soon will resolve this issue. In the meantime you can change the servlet version back to "2.5" (in BuildConfig.groovy) which will resolve this issue.

The drawback of changing the servlet version to 2.5 is that it cannot be deployed to Glassfish application server so the ugly workaround is change to 2.5 and use "run-app". When you want to deploy to glassfish change the servlet version to "3.0" in BuildConfig.groovy, run "war" and then deploy the war to Glassfish. Change it back to "2.5" to run on local dev machine again.




回答3:


Check the FAQ

Q: OMG I get OutOfMemoryErrors or PermGen Space errors when running Grails in development mode. What do I do?

Since Grails 0.6, Grails automatically re-compiles Java sources and domain classes using pre-compilation and then a server restart. This can lead to permgen space running out if the server is run for a long time and many changes are made. You can disable this feature if it is not important to you with:

grails -Ddisable.auto.recompile=true run-app

There is also a problem with Grails 0.6 on Windows where you get OutOfMemoryErrors during a period of activity in development mode due to the re-compilation. This may be solved in SVN head, but if you see this problem the above option can also help.

Easiest just to restart your application server when it happens.




回答4:


In the STS IDE set as per following:

-XX:MaxPermSize=512m -XX:PermSize=128m

I hope it helps.



来源:https://stackoverflow.com/questions/6412153/grails-permgem-error

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