My tomcat application crashed due to memory leak.
I want to take the heap dump on the crashed system/jvm.
Is it possible? I am using windows/tomcat 6
How?
The process does not exists anymore. So there is no heap to dump.
Use '-XX:+HeapDumpOnOutOfMemoryError' for the next time.
You can get the heap dump at runtime by:
jmap -dump:live,format=b,file=heap.dump
You can't get a heap dump on a process that is no longer running. Next time you start Tomcat, you're going to have to edit the file in the /bin directory called catalina.sh first so that it contains options to automatically dump the heap if it runs out of memory.
What you need to do is to edit the JAVA_OPTS variable so that contains the JVM options you need. So near the top of the file, after JAVA_OPTS has been created, you need to do something like
JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError"
You can also take heap dumps using JConsole, but in order to do this, you need to know roughly when Tomcat is running out of memory in order for the heap dump to help you diagnose the problem.
If your application is not responding but the JVM is still limping, you may try using JConsole and trigger a Heap Dump. Search for Heap Dump on this link
Related
In our Environment the tomcat server got hanged frequently then we increase the heap and restart the tomcat.
There is any another way to analyze the heap dumps in tomcat??
can we create the heap dumps in tomcat? if possible how?
Thanks
Surya
First, you should analyze exactly what causes your Tomcat to hang. There are many reasons which can cause an application to "hang", e.g. dead locks, long GC pauses, etc.
Looking at the heap dump makes sense if your Tomcat crashes with an OutOfMemoryError.
In that case you can use a tool like MAT to analyze the heap dump.
You can create heap dumps any time with jcmd <pid> GC.heap_dump <file>. You can also set the VM option -XX:+HeapDumpOnOutOfMemoryError. This will dump the heap automatically when you get an OutOfMemoryError.
"-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp" This parameter will help to take heap dump automatically when server limit is reached.
http://www.oracle.com/technetwork/java/javase/clopts-139448.html#gbzrr
I can see detailed information on above link but, "OutOfMemoryError" message prints so many times in my server log times.
So, If the error msg occurs multiple times, will JVM take multiple heap dump ?
Regards,
Peter
The oracle jvm creates a heap dump only on the first OOM when this flag is specified. However you can manually create multiple heapdumps if the jvm process is still alive and responsive. A little bit of googling:
-XX:+HeapDumpOnOutOfMemoryError not creating hprof file in OOM
It depends on the JVM. I think the Oracle JVM only dumps once.
I have used Thread Pool for New IO server design . I have used newFixedThreadPool as a Executors factory method for thread pool creation. My server is throwing Exception when i execute my server for 20 to 30 minute . how to handle this exception.
java.lang.OutOfMemoryError: Java heap space
Obviously you are using too much memory, so now you need to find out why. Without your source it is very hard to to say what is wrong, but even with source it can be problematic when the program start to become complex.
What I have found helpful is to take memory dumps and look at them in tools such as Memory Analyzer (MAT). It can even compare several dumps to see what kind of objects are allocated. When you get an idea of what objects exists which you don't think should be there you can use the tool to see what roots it has (which objects has a reference to it).
To get a memory dump form a running java program use jmap -dump:format=b,file=heap.bin and to automatically get a memory dump when your program gets and OutOfMemoryError you can run it with java -XX:+HeapDumpOnOutOfMemoryError failing.java.Program
normally its java -Xms5m -Xmx15m MyApp
-Xms set initial Java heap size
-Xmx set maximum Java heap size
and in eclipse under java run configuration as VM argument
-Xms128m
-Xmx512m
-XX:permSize=128M
-XX:MaxPermSize=384M
You can defnitely try increasing the HEAP SIZE and check if you are getting the issue.
However, I would prefer you to try profiling your application to find out why your heap size and where the memory is being consumed.
There are few Profilers available as open source you can try.
I am facing "Out Of Memory Error Exception" while running a web service application over jboss 4.2
how can I increase the memory of jboss ? and will this solve the problem ?
You should first confirm if the memory usage is not abnormal. If it is not, it is probably a good idea to increase the memory allocation. JBoss default memory allocation is rather small at the default setting.
You want to confirm that the memory shortage is heap shortage (it could be permgen etc. if it is permgen, please refer to general OOME (OutOfMemoryError) questions). If you are using Java 1.6 you just need to read the exception message to determine this.
Once you confirm it is a heap shortage, it is advisable to confirm that there is no memory leak occurring before you go for a bigger heap size. To do this, you can attach a heap monitor like visualVM and monitor heap usage under stress (for more information see this: http://olex.openlogic.com/wazi/2009/how-to-fix-memory-leaks-in-java/).
Once you are done with this, and you are sure that you have a legitimate heap shortage, you can edit run.conf (Linux) or run.bat (Windows) to allocate more heap. You can search for JAVA_OPTS and change -Xmx512m to something like -Xmx1024m.
You can increase the memory for JBoss, but make sure to find out why it uses more memory than expected to make sure the problem doesn't come back to bite you.
Set this in your shell before launching JBoss while experimenting:
JAVA_OPTS="-Xms512m -Xmx1024m"
I am running load against Tomcat 6 running on Java 6. I want to collect a heapdump of the Java heap while the Tomcat server is under load. I normally use jmap -dump to collect my heapdumps.
However, when I try to do this when Tomcat is handling a high load I find that the heapdump collection fails.
Is jmap the best tool for collecting a heap dump from a process under load? What are the possible causes which would cause jmap to fail to collect a heapdump?
If jmap is not the best tool - what is better?
It is entirely acceptable to me for jmap (or some other tool) to stop the world within the Java process while the heap dump is taken.
Is jmap the best tool for collecting a heap dump from a process under load?
I think: No it isn't. From this link:
NOTE - This utility is unsupported and
may or may not be available in future
versions of the JDK.
I've also found jmap can pretty temperamental. If you're having problems:
Try it again. It often manages to get a heap dump after a couple of attempts if it first fails
Use the -F option
Add -XX:+HeapDumpOnOutOfMemoryError as a standard configuration to proactively take heap dumps when an OOM error is thrown
Run Tomcat interactively and add the heap dump on ctrl-break option. This gives you a thread dump too, something you'll probably need anyway
If your heap size is especially large and you have a repeatable condition, temporarily lower your heap size. It makes the resulting file much easier to handle, takes less time and is more likely to succeed
I have found that running Tomcat with a JMX port allows me to take a remote heapdump using visualvm. This succeeded for me when jmap failed.