user238021
user238021

Reputation: 1221

How to debug an OutOfMemoryException in a webapp

I am trying to debug an out of memory error. When I do a heap dump with Jmap and analyze the results with eclipse Mat - I see the following.

7,677 instances of "java.lang.Class", loaded by 
"<system class loader>" occupy 48,094,720 (23.99%) bytes. 

Biggest instances:

class blah.BlahService$$EnhancerByCGLIB$$4a0a7d43 @ 0x2aaab06d9668 
- 2,067,096 (1.03%) bytes. 

BlahService is a spring service with @Service annotation. All service classes are Singleton in spring - one per IOC per bean - So why would this class be a top suspect.

I also see

One instance of "org.apache.jasper.servlet.JspServlet" loaded by 
"org.apache.catalina.loader.StandardClassLoader @ 0x2aaac17bc260" occupies 42,724,168 
(21.31%) bytes. The memory is accumulated in one instance of 
"java.util.concurrent.ConcurrentHashMap$Segment[]" loaded by "<system class loader>".

what does this mean?

Upvotes: 2

Views: 527

Answers (3)

Jigar Parekh
Jigar Parekh

Reputation: 6283

i have used java profilers but i am not satisfied with output for actual performance tuning and memory usage currently we have been switched to java melody. This not only help performance optimization in dev but also in production system. Java melody is very easy to integrate and configure and in production you can enable or disable by just updating web.xml

Upvotes: 0

Nikem
Nikem

Reputation: 5784

OutOfMemoryError usually signifies one of the two problems: 1. Either you have too little memory for your application needs. Then you need increase the heap size for your server using Xmx startup parameter 2. Or you have a memory leak in your application or in one of the 3rd party libraries it uses. To track memory leak is not an easy task without prior experience. I can recommend Plumbr. It is quite easy to use and precise tool for monitoring memory leaks.

Upvotes: 1

rekiem87
rekiem87

Reputation: 1573

Yep, that error sows up when it's too late to do something to fixed it, that because once the heap gets filled the JVM simply can't do anything since it can't create objects to do something, in other hand, since you're using Spring i guess you're doing a Web System, in that case all you have to do is give more heap space at the beginning in the deploy command (it's something like '-Xms:256') and have planned how many resources your app will be need, because it's a fact, if the memory gets filled the system is going to break down

Upvotes: 0

Related Questions