mvn jetty:run出现OutOfMemoryError: PermGen space的处理

在eclipse内使用 mvn jetty:run 出现OutOfMemoryError: PermGen space,异常堆栈如下:
2012-05-07 09:30:54.218:WARN:oejs.ServletHandler:Error for /bs/bc/template/loadTplConfigParam
java.lang.OutOfMemoryError: PermGen space
at java.lang.Throwable.getStackTraceElement(Native Method)
at java.lang.Throwable.getOurStackTrace(Throwable.java:591)
at java.lang.Throwable.getStackTrace(Throwable.java:582)
at org.codehaus.plexus.classworlds.realm.ClassRealm.findResource(ClassRealm.java:264)
at java.lang.ClassLoader.getResource(Unknown Source)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadResourceFromImport(ClassRealm.java:426)
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.getResource(SelfFirstStrategy.java:60)
at org.codehaus.plexus.classworlds.realm.ClassRealm.findResource(ClassRealm.java:268)
at java.lang.ClassLoader.getResource(Unknown Source)
at org.eclipse.jetty.webapp.WebAppClassLoader.getResource(WebAppClassLoader.java:363)
at java.lang.Class.getResource(Unknown Source)
at freemarker.cache.ClassTemplateLoader.getURL(ClassTemplateLoader.java:143)
at freemarker.cache.URLTemplateLoader.findTemplateSource(URLTemplateLoader.java:75)
at freemarker.cache.MultiTemplateLoader.findTemplateSource(MultiTemplateLoader.java:111)
at freemarker.cache.TemplateCache.acquireTemplateSource(TemplateCache.java:600)
at freemarker.cache.TemplateCache.findTemplateSource(TemplateCache.java:576)
at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:347)
at freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:235)
at freemarker.template.Configuration.getTemplate(Configuration.java:487)
at freemarker.template.Configuration.getTemplate(Configuration.java:452)
at org.apache.struts2.dispatcher.Dispatcher.sendError(Dispatcher.java:735)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:506)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1331)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1331)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:477)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:521)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227)
2012-05-07 09:30:57.641:WARN:oeji.nio:handle failed
java.lang.OutOfMemoryError: PermGen space
at java.lang.Throwable.getStackTraceElement(Native Method)
at java.lang.Throwable.getOurStackTrace(Throwable.java:591)
at java.lang.Throwable.getStackTrace(Throwable.java:582)
at org.eclipse.jetty.util.log.StdErrLog.format(StdErrLog.java:547)
at org.eclipse.jetty.util.log.StdErrLog.format(StdErrLog.java:417)
at org.eclipse.jetty.util.log.StdErrLog.warn(StdErrLog.java:288)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:482)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:925)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:857)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:76)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:609)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:45)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534)
at java.lang.Thread.run(Unknown Source)

处理方法:
VM参数中添加如下配置:
-server -Xms256m -Xmx512m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+CMSClassUnloadingEnabled -XX:+PrintGCDetails -Xloggc:%M2_HOME%/gc.log -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=%M2_HOME%/java_pid.hprof

其中参数说明如下:
-XX:+CMSPermGenSweepingEnabled : 允许permgenspace的垃圾回收
-XX:+CMSClassUnloadingEnabled : allows the garbage collector to remove even classes from the memory
-XX:PermSize=256M -XX:MaxPermSize=256M : raises the amount of memory allocated to the permgenspace
 
转自:http://rongjih.blog.163.com/blog/static/33574461201247102329705/

你可能感兴趣的:(eclipse)