我正在使用Tomcat 7部署我的应用程序(使用spring控制器),我发现在我的服务器上有时会发生以下异常。请帮忙。要明白这与我的服务器内存有关,但可能是我错了。我也在最后给出了我的ulimit细节。这种情况有时只发生,而不是总是发生。没有特定的重复场景或发生间隔......
我使用的是Red Hat 6(64位)操作系统 设置的JVM细节为:-Xms1024m -Xmx1024M -XX:PermSize = 64M -XX:MaxPermSize = 512m
27 Dec 2013 10:56:15,462 DEBUG [http-bio-5004-exec-41] DispatcherServlet:910 - Could not complete request
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.OutOfMemoryError: unable to create new native thread
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:972)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.atmosphere.util.AtmosphereFilterChain.doFilter(AtmosphereFilterChain.java:171)
at org.atmosphere.util.AtmosphereFilterChain.invokeFilterChain(AtmosphereFilterChain.java:132)
at org.atmosphere.handler.ReflectorServletProcessor$FilterChainServletWrapper.service(ReflectorServletProcessor.java:359)
at org.atmosphere.handler.ReflectorServletProcessor.onRequest(ReflectorServletProcessor.java:204)
at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:237)
at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:163)
at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:101)
at org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket.doService(Tomcat7Servlet30SupportWithWebSocket.java:67)
at org.atmosphere.container.TomcatWebSocketUtil.doService(TomcatWebSocketUtil.java:95)
at org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket.service(Tomcat7Servlet30SupportWithWebSocket.java:62)
at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1675)
.......
Caused by: java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:691)
at sun.net.www.http.KeepAliveCache$1.run(KeepAliveCache.java:112)
at sun.net.www.http.KeepAliveCache$1.run(KeepAliveCache.java:96)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.http.KeepAliveCache.put(KeepAliveCache.java:95)
at sun.net.www.http.HttpClient.putInKeepAliveCache(HttpClient.java:353)
at sun.net.www.http.HttpClient.finished(HttpClient.java:341)
at sun.net.www.http.KeepAliveStream.close(KeepAliveStream.java:100)
at sun.net.www.MeteredStream.justRead(MeteredStream.java:93)
at sun.net.www.MeteredStream.read(MeteredStream.java:135)
at java.io.FilterInputStream.read(FilterInputStream.java:133)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3052)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3046)
at org.springframework.util.FileCopyUtils.copy(FileCopyUtils.java:112)
at org.springframework.util.FileCopyUtils.copyToByteArray(FileCopyUtils.java:164)
at org.springframework.web.client.DefaultResponseErrorHandler.getResponseBody(DefaultResponseErrorHandler.java:102)
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:87)
at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:494)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:451)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:409)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:385)
at com.payoda.appviewx.web.adapter.rest.AdapterBase.sendRequest(AdapterBase.java:90)
at com.payoda.appviewx.web.adapter.rest.DiscoverDeviceAdapter.discoverDeviceByRange(DiscoverDeviceAdapter.java:63)
at com.payoda.appviewx.web.controller.DeviceController.getDiscoverDeviceUsingRange(DeviceController.java:137)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
... 71 more
ulimit的详细信息如下:
Ulimit details
----------------
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 127515
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 20000
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 65536
cpu time (seconds, -t) unlimited
max user processes (-u) 1024
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
答案 0 :(得分:0)
在$ CATALINA_HOME / bin中创建文件“setenv.sh”(“setenv.bat”),将以下内容放入其中:
set CATALINA_OPTS="-Xms512m -Xmx1024m"
然后重启tomcat。
如果无法解决问题,请尝试将参数“Xms”和“Xmx”更改为更高的值。
重要提示:不要忘记将可执行位设置为“setenv.sh”(如果您使用的是Linux)。
答案 1 :(得分:0)
与ulimit无关; JVM强加了自己的最大内存限制。例如,从命令行启动java时,您可以使用-Xmx10g
为JVM提供10Gb最大内存。对于Tomcat,放置设置的位置取决于您拥有的操作系统以及如何安装Tomcat。
例如,在使用debian包中的Tomcat的Debian上,您通常会编辑/etc/default/tomcat...
并将JAVA_OPTS="-Xmx10g"
放入其中(或者您想要的更多)。