Tomcat服务org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.OutOfMemoryError: Java heap space

A long-running project, recently suddenly being given: OOM (java.lang.OutOfMemoryError: Java heap space), abnormal follows

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.OutOfMemoryError: Java heap space
    at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1305)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:979)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:869)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:217)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:217)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:184)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:105)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:361)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1080)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:75)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:757)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.OutOfMemoryError: Java heap space

 

The program runs into the heap memory (Stack) and stack memory (Heap) Memory

With c knowledge of the language a little early to analyze the problem, understood as follows:

1, stack memory characteristic is fast with a fast pin does not need to manually release management; (a network problem, the file system, a message cycle, unreasonable recursion stack operations also cause too much overhead even overflow StackOverflowError)

2, the characteristics of heap memory is with who pin (c language version: Who who apply for release)

So according to what exceptions to the screening, the program must use unreasonable use of memory cause the whole problem, but an exception is usually the hardware level OOM exception.

Checked the server, 32G memory, this problem should not arise.

 

Since the tomcat service is run by the way, more memory allocated as follows

Initial memory pool (heap memory initialization) parameter 128M correspond -Xms

Maximun memory pool (maximum heap memory) -Xmx parameter corresponding to 256M

As the Dragon Boat Festival holiday period, incremental data accumulated to 330,000, and no one to deal with, the program attempts to run automatically when the application heap memory to peaking (256M) , it reported this error.

Solution: Increase the heap memory initialization, the maximum heap memory

Initial memory pool instead 1024M

Maximun memory pool 10240M

Also add the following parameters inside the Java Option

-XX: PermSize = 256M   // initialize class load memory pool size 
-XX: MaxPermSize 256M = // maximum class load memory pool size 
-XX: MaxNewSize = 256M

After optimization of the following

Reference: Tomcat startup memory settings [Reserved]

 

Guess you like

Origin www.cnblogs.com/passedbylove/p/11002389.html