2

I am facing issue in my web application which uses Spring + Hibernate .

I am randomly getting error

java.lang.OutOfMemoryError: GC overhead limit exceeded

when web application is running in tomcat

I tried to get Heap dump and did analysis of heap dump using Eclipse MAT

Here are my findings

Object org.hibernate.impl.SessionFactoryObjectFactory holds 86% of the memory , this object’s Fashhashmap instance holds more than 100000 Hashmaps. Inside the every Hashmap there is an instance of org.hibernate.impl.SessionFactoryImpl , It seems org.hibernate.impl.SessionFactoryImpl is loaded several times and stored inside org.hibernate.impl.SessionFactoryObjectFactory ‘s Fashhashmap

Can somebody help me in finding root cause for this issue and suggest some solution to fix this.

Lavesh
  • 21
  • 1
  • 2
  • 2
    Can you show us how you configure Hibernate it in Spring, how do you manage transactions and some example Hibernate query? Can be anonymized. – Tomasz Nurkiewicz Apr 12 '12 at 17:47

2 Answers2

1

Well, even if you are getting that SessionFactoryObjectFactory holds 86% of the memory, it doesn't seem the cause to me.The first thing is before relying on any memory analysis tool, we should first understand how this tool predict out the outofmemory issues. Memory tools just try to capture the instant HIKES which are shown in application once you run that tool. I am pretty sure that you would get the same error logs saying but with different causes mentioned by the tool that Catalina web class loader is accessing major amount of memory, which is obvious and expected.

So just I want to figure out that, instead of relying on any such tools (which may right in particular cases/implementations), you try to dig your app source code and try to find where the unnecessary temp objects are being created.

For debugging purpose, you may turn on the JVM option - -XX:-PrintGCDetails to view what exactly GC is collecting.

See these posts/references for more info - http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html#Options java.lang.OutOfMemoryError: GC overhead limit exceeded

Community
  • 1
  • 1
Ved
  • 8,577
  • 7
  • 36
  • 69
0

Well your GC thread is spending 98% or more of processor time trying to clean up objects.

The idea of the Factory pattern is to return a non null instance of the object you wish to create, which is generally done by returning the same instance once one has been instantiated.

Now it could be that you have 100,000 different sessions or whatnot but I doubt that is correct, hence you need to check your code to make sure that the Factory method calls are being down correctly, and likely without a local copy being cached.

If you do indeed have 100,000 sessions then take a good look at the methods which are creating them. Break long methods up so that loops and while structures are separated by method calls so that method local variables can be cleaned up once out of scope.

Also ensure that these smaller methods are not final as the compiler will stitch final methods together into a single stack frame as an optimisation technique.

Chaffers
  • 176
  • 9