Java – how to solve java out of memory error in amazon ec2 linux servers

amazon ec2java

We are using Fedora-8 64 bit in Amazon EC2 and our Java application is running on the IBM JRE. Now we are getting a Java hang "out of memory" error. Our memory is 7.6 GB and we have allotted heap memory -Xms3000M -Xmx3000M. We are still getting the same problem. The question is, if I increase the heap size then will this problem be rectified? Or is there any other alternative to solve this problem?

Best Answer

3G is sound like large enough amount of memory assigned to java heap, you may get not heap out of memory but permanent generation (PermGen). Consider increase PermSize and MaxPermSize.

To solve problem you may need monitor how fast and which part of JVM memory is growing. Use JMX console, also you may look deeper - take snapshot of running java heap and analyse it to define problematic places (http://www.eclipse.org/mat/) also thread dump and object histogram may help.