2009年3月15日星期日

WLS_036:常见故障之四:Stack Overflow Error

Stack Overflow Error是我们经常所说的“栈溢出异常”,它会导致JVM处在一个不稳定的状态,最终导致JVM Crash。因此,我们有必要了解这种错误的成因及解决办法。

1. 典型现象
(1)抛出异常java.lang.StackOverflowError。

2. 产生原因
(1)递归调用

3. 诊断步骤
(1)增加-XX:+ShowMessageBoxOnError,在出现异常的时候获取Thread Dump。

4. 解决方案
(1)避免使用递归调用或减少递归的层数。

5. 如何模拟Stack Overflow Error
(1)编写一个递归方法。
(2)获取Thread Dump,发现该方法递归调用的痕迹:
"ExecuteThread: '13' for queue: 'weblogic.kernel.Default'" daemon prio=5 tid=0x02f1f2d8 nid=0x700 waiting on condition [0x037ef000..0x037efd68]
at java.lang.Thread.sleep(Native Method)
at troubleshooting.servlets.StackOverFlow.recurse(StackOverFlow.java:65)
at troubleshooting.servlets.StackOverFlow.recurse(StackOverFlow.java:68)
at troubleshooting.servlets.StackOverFlow.recurse(StackOverFlow.java:68)
at troubleshooting.servlets.StackOverFlow.recurse(StackOverFlow.java:68)
at troubleshooting.servlets.StackOverFlow.recurse(StackOverFlow.java:68)
at troubleshooting.servlets.StackOverFlow.recurse(StackOverFlow.java:68)
at troubleshooting.servlets.StackOverFlow.recurse(StackOverFlow.java:68)
at troubleshooting.servlets.StackOverFlow.recurse(StackOverFlow.java:68)
at troubleshooting.servlets.StackOverFlow.recurse(StackOverFlow.java:68)
at troubleshooting.servlets.StackOverFlow.recurse(StackOverFlow.java:68)
at troubleshooting.servlets.StackOverFlow.recurse(StackOverFlow.java:68)
at troubleshooting.servlets.StackOverFlow.recurse(StackOverFlow.java:68)
at troubleshooting.servlets.StackOverFlow.recurse(StackOverFlow.java:68)
at troubleshooting.servlets.StackOverFlow.service(StackOverFlow.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1077)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:465)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:348)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:7047)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3902)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2773)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)

没有评论: