2011-06-20 34 views
4

我需要此問題的幫助。我需要有人向我解釋爲什麼會發生這種情況,以及如何預防或避免這種情況。Grails PermGem錯誤

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. 
+0

您爲Grails應用程序使用哪些內存設置? permGen空間的標準64M對於典型的grails應用程序來說是不夠的。 – Ruben

回答

19

PermGen是用於加載類的JVM內存區域。

隨着應用程序的執行,它會使用越來越多的內存,特別是在調試環境中時,如果大量使用閉包,則會佔用更多內存。

解決這個問題的方法是添加更多!

這是通過在啓動應用程序時將一個或兩個參數傳遞給JVM來完成的。

的參數是:

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

(調整值,以您的特定需求)

的PermSize將是PermGen的的初始大小,而MaxPermSize參數將是最大尺寸在其在投你一個例外之前會增加。

默認情況下,它被設置爲64M,如果你有一個'真實'的應用程序,這並不是很多。

注意:您total memory usage將是:Heap size + Perm Size

+5

+1支付「注意」! – user3111525

0

查看常見問題解答

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

因爲Grails的0.6,Grails的自動重新編譯Java源代碼,並使用預編譯,然後重新啓動服務器 域類。如果服務器長時間運行並進行了許多更改,則此 可能導致永久磁盤空間不足。如果 不是對你很重要,你可以禁用此功能:

Grails的-Ddisable.auto.recompile =真正運行的應用程序

也有與Windows 0.6的Grails你在哪裏得到 OutOfMemoryError異常的問題在開發模式期間,由於 需要重新編譯。這可能會在SVN頭部解決,但如果你看到 這個問題上述選項也可以幫助。

最簡單的就是當它發生時重啓你的應用服務器。

1

如果您正在使用的Servlet 3.0版那麼即使增加您的記憶不會有任何幫助,因爲它是用Groovy編譯器有問題。即將發佈的新版本1.8.2/1.9(?)將解決此問題。與此同時,您可以將servlet版本更改回「2.5」(在BuildConfig.groovy中),這將解決此問題。

將servlet版本更改爲2.5的缺點是無法將其部署到Glassfish應用程序服務器,因此醜陋的解決方法將更改爲2.5並使用「run-app」。當您想部署到glassfish時,將BuildConfig.groovy中的servlet版本更改爲「3.0」,運行「war」,然後將戰爭部署到Glassfish。 將其更改回「2.5」以再次在本地開發機器上運行。

0

在STS IDE設置按如下:

-XX:MaxPermSize參數=512米-XX:PermSize =128米

enter image description here

我希望它能幫助。