tomcat中的UncaughtExceptionHandler

时间:2012-12-05 07:14:27

标签: java multithreading tomcat out-of-memory

执行我的Web应用程序时,我在tomcat源代码中出现OutOfMemoryError。

java.lang.OutOfMemoryError:Java堆空间

java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Unknown Source)
at java.lang.AbstractStringBuilder.expandCapacity(Unknown Source)
at java.lang.AbstractStringBuilder.append(Unknown Source)
at java.lang.StringBuilder.append(Unknown Source)
at com.source.server.wc.common.SupportAction.execute(SupportAction.java:252)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.source.server.wc.common.AuthenticationFilter.doFilter(AuthenticationFilter.java:300)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.source.server.wc.common.EncodingFilter.doFilter(EncodingFilter.java:70)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:568)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)    

我补充说 Thread.currentThread()。setDefaultUncaughtExceptionHandler(new OOMEHandler()); 在我的主线程中,现在我从webclient执行任务时得到OOMError,但OOMError没有被UncaughtExceptionHandler捕获。

我怎么能抓住它?

1 个答案:

答案 0 :(得分:0)

UncaughtExceptionHandler也会抓住OutOfMemoryError。你似乎正在设置它的相关性。因此,要么其他进程之后调用它(您可以通过设置函数的断点进行检查),或者TomCat在Thread上设置了自己的一个,您可以通过调用{{1}来检查它}。如果没有设置,这将返回Thread.currentThread().getUncaughtExceptionHandler()

另请注意null是静态的,因此您不应该在对象上调用它而不是在类上,因此:

setDefaultExceptionHandler()

而不是

Thread.setDefaultUncaughtExceptionHandler(new OOMEHandler());