简体   繁体   中英

Tomcat7 java.lang.OutOfMemoryError: Java heap space

I am running tomcat7 service which process quite a big load from customers. 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:

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?

Currently my tomcat is runnning under default configurations I've never increased heap size yet.

We are receiving around 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,
java.lang.OutOfMemoryError: Java heap space error will occur.

Solution 1 : You should increase the availability of that resource . When your application does not have enough Java heap space memory to run properly. For that, you need to alter your JVM launch configuration and add the following:

-Xmx1024m

The above configuration would give the application 1024MB of Java heap space. You can use g or G for GB, m or M for MB, k or K for KB. For example all of the following are equivalent to saying that the maximum Java heap space is 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. If you wish to solve the underlying problem with the Java heap space instead of masking the symptoms, you have several tools available.
For Example: Plumbr tool. Among other performance problems it catches all java.lang.OutOfMemoryErrors and automatically tells you what causes them. You can go through about other available tools. And the choice is yours!


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.

  2. If 1 does not working, it could be a bug in your application that might be preventing garbage collection. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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