1

Hello i have taken the thread dump for my web application which is giving out of memory again and again using the JSTACK but i am little bit confused that how to find the correct culprit thread can some one give the tips that how to analyze the dump file.

Rohitesh
  • 1,514
  • 7
  • 28
  • 51

2 Answers2

0

Use VisualVM which is included with the JDK.

0

When you have a OutOfMemoryError, the first step is to read the associated message. It explains the cause of the error : heap, perm, thread,...

Depending on the cause, you have to check the configuration of the space : -Xms and -Xmx for the heap, -XX:PermSize and -XX:MaxPermSize for the perm (Java 7-), -XX:MaxMetaspaceSize for the metaspace (Java 8+),... The config may be too low for your need.

After that, use tools to understand how the memory is consumed. VisualVM is great, it provides metrics on the memory, helps you to make heap dumps or to profile the memory (not in production). You may add the -XX:+HeapDumpOnOutOfMemoryError option in your startup script so that the heap dump will be automatically generated when you run an OutOfMemoryError.

If you have memory leaks, I suggest to use more advanced (and not free) profiling tools such as JProfiler or YourKit.

Alexis Hassler
  • 752
  • 5
  • 16
  • If i am getting the OutOfMemory because of the thread i.e. i am getting the message unable to create the native thread then can you suggest me how to move forward. – Rohitesh Feb 23 '15 at 11:39
  • I guess that you're on a 32bits OS. The size of a process has a limite between 2 and 3 or 4 GB, depending on the OS. Each thread uses a amount of memory, set by -Xss. When the app starts a new thread and the limit is reached, a OutOfMemoryError is thrown. you seem to be in this case. The solutions : 1) move to a 64bits OS; 2) decrease the Xss value (try -Xss256k or -Xss128k); 3) decrease the -Xms and/or -XX:MaxPermSize values. – Alexis Hassler Feb 23 '15 at 12:20
  • thanks for the answer but i am using 64bit not 32 bit OS actually i moved my application to a complete new server from the old server after that the problem started might be the problem related to the window job scheduler. – Rohitesh Feb 24 '15 at 04:58
  • by the way it is a standalone program using quartz to schedule the jobs. – Rohitesh Feb 24 '15 at 05:12
  • OK. You should then check the number of threads in your VM. You may have reach a system limit on this side. – Alexis Hassler Feb 24 '15 at 07:00
  • sir is this is limiting from the OS side if so how can i check that configuration because from my application side i am not giving the number of thread limit by default it will be 200 only in server.xml. – Rohitesh Feb 24 '15 at 07:30
  • In server.xml, you setup the number of threads associated to the Tomcat connectors, not the overall number. Quartz has its own threads. – Alexis Hassler Feb 24 '15 at 07:48