简体   繁体   English

Tomcat7 java.lang.OutOfMemoryError:Java堆空间

[英]Tomcat7 java.lang.OutOfMemoryError: Java heap space

I am running tomcat7 service which process quite a big load from customers. 我正在运行tomcat7服务,这会给客户带来很大的负担。 I left application during a weekend and when I back I noticed that tomcat CPU usage increased to 99% and in the logs I have found following errors: 我在一个周末离开了应用程序,当我回来时,我注意到tomcat CPU使用率增加到99%,在日志中我发现以下错误:

Exception in thread "http-bio-8080-exec-908" java.lang.OutOfMemoryError: Java heap space
Exception in thread "http-bio-8080-exec-948" java.lang.OutOfMemoryError: Java heap space

Does it means that at the time I've got OutOfMemory exception I had 908 and 948 opened active threads? 这是否意味着当我有OutOfMemory异常时,我有908和948打开活动线程?

Currently my tomcat is runnning under default configurations I've never increased heap size yet. 目前我的tomcat在默认配置下运行我还没有增加堆大小。

We are receiving around 200 queries/sec . 我们200 queries/sec接收大约200 queries/sec

My hardware:
CPU : Intel(R) Xeon(R) CPU           X5650  @ 2.67GHz
Memory: 2GB

Could you please point me into right direction, what should I look at in order to resolve this issue. 你能否指出我正确的方向,我应该看看为了解决这个问题。

Thanks for any help! 谢谢你的帮助!

When your JVM runs out of a particular resource, 当您的JVM用完特定资源时
java.lang.OutOfMemoryError: Java heap space error will occur. java.lang.OutOfMemoryError: Java heap space将发生java.lang.OutOfMemoryError: Java heap space错误。

Solution 1 : You should increase the availability of that resource . 解决方案1:您应该增加该资源的可用性 When your application does not have enough Java heap space memory to run properly. 当您的应用程序没有足够的Java堆空间内存来正常运行时。 For that, you need to alter your JVM launch configuration and add the following: 为此,您需要更改JVM启动配置并添加以下内容:

-Xmx1024m

The above configuration would give the application 1024MB of Java heap space. 上面的配置将为应用程序提供1024MB的Java堆空间。 You can use g or G for GB, m or M for MB, k or K for KB. 您可以使用g或G表示GB,m或M表示MB,k或K表示KB。 For example all of the following are equivalent to saying that the maximum Java heap space is 1GB: 例如,以下所有内容相当于说最大Java堆空间为1GB:

 -Xmx1073741824 
 -Xmx1048576k 
 -Xmx1024m 
 -Xmx1g 


Solution 2 : If your application contains a memory leak , adding more heap will just postpone the java.lang.OutOfMemoryError: Java heap space error. 解决方案2:如果您的应用程序包含内存泄漏 ,则添加更多堆只会推迟java.lang.OutOfMemoryError:Java堆空间错误。 If you wish to solve the underlying problem with the Java heap space instead of masking the symptoms, you have several tools available. 如果您希望解决Java堆空间的基本问题而不是屏蔽症状,那么您可以使用多种工具。
For Example: Plumbr tool. 例如:Plumbr工具。 Among other performance problems it catches all java.lang.OutOfMemoryErrors and automatically tells you what causes them. 在其他性能问题中,它捕获所有java.lang.OutOfMemoryErrors并自动告诉您导致它们的原因。 You can go through about other available tools. 您可以查看其他可用工具。 And the choice is yours! 而选择权归你的!

Source: 资源:
https://plumbr.eu/outofmemoryerror/java-heap-space https://plumbr.eu/outofmemoryerror/java-heap-space

There could be couple of reasons, 可能有几个原因,

  1. Since you have not increased the default memory allocation, with high load, it probably won't have enough resources to serve all requests and some are obviously running out of memory. 由于你没有增加默认的内存分配,在高负载的情况下,它可能没有足够的资源来为所有请求提供服务,而且有些资源显然内存不足。 So first thing to try is to tweak the jvm memory configuration. 首先要尝试的是调整jvm内存配置。

  2. If 1 does not working, it could be a bug in your application that might be preventing garbage collection. 如果1不起作用,则可能是应用程序中可能阻止垃圾回收的错误。 You might want to run your application with a profiler attached to see what objects are collected over time and use that information to debug. 您可能希望在附加了分析器的情况下运行应用程序,以查看随时间收集的对象并使用该信息进行调试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM