Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get Tomcat running as a service to dump heap?

I am attempting to have Tomcat, which is currently running as a service on a Windows 2003 box, dump heap on an OutOfMemoryError.

(Tomcat is running Hudson, which is reporting a heap space problem at the tail end of my build. Running the build manually produces no such error. The Hudson guys need a heap dump to get started.)

As instructed elsewhere, I've told the Apache Service Monitor to configure the JVM it uses to run Tomcat to dump heap when an OutOfMemoryError is encountered by adding the following to the JVM options: -XX:+HeapDumpOnOutOfMemoryError Then I run the build again. Sure enough, it reports there was a heap error. I scan the entire disk looking for the default java_pid123.hprof file (where obviously 123 is replaced by the PID of the JVM). No .hprof files exist anywhere.

I am caught in a catch 22: I need the heap dump for the Hudson guys to fix their memory leak, but I can't get the heap dump if I run Hudson under Tomcat.

Is there some special way, when Tomcat is running as a Windows service, to get a heap dump from it on an OutOfMemoryError?

The other thing I've tried is to tell it, on the Startup and Shutdown tabs, to use the "Java" option instead of the "jvm" option. I believe this should tell the Service Manager to attempt to start Tomcat with a Java executable command instead of launching the jvm.dll directly. When I do this, the service won't start.

Surely someone else has had a similar problem?

like image 580
Laird Nelson Avatar asked Jan 31 '10 15:01

Laird Nelson


People also ask

What is Tomcat as a service?

Tomcat's Service applicationsTomcat6 is the actual service wrapper program that allows Tomcat to be run as a service, and will run entirely in the background after it has been installed, and accepts a long list of command line parameters that allow precise configuration of the Tomcat service.

How do I get a heap dump from a running JVM?

Heap dump = memory contents for the JVM process output to a binary file. To take a thread dump on Windows, CTRL + BREAK if your JVM is the foreground process is the simplest way. If you have a unix-like shell on Windows like Cygwin or MobaXterm, you can use kill -3 {pid} like you can in Unix.

How do I run Tomcat 8 as a service?

1) Open a command prompt, go to the bin folder of the apache tomcat and run "service. bat install". If the CATALINA_HOME, JAVA_HOME and JRE_HOME are correctly configured, the 'Tomcat' service will be installed successfully. 2) Go to Services, and look for Apache Tomcat service.


1 Answers

When java process running as window service you can generate the heapdump using below steps,

  1. Run the command console as Administrator
  2. version of JDK (for jmap command) and JRE (Java app run environment) should be same.
  3. Get the PID no of running window process for that java application from task manager
  4. Execute below command

jmap -dump:file=d:\heapdump\myHeapDump.hprof -F #PID_No#

If got any exception with JDK/JRE 7 try the same with JDK/JRE 8 Actually I faced some issue in jmap with JDK 7, but when i moved to JDK 8, I were able to successfully generate the heap dump using same command

like image 51
Anil Agrawal Avatar answered Nov 07 '22 03:11

Anil Agrawal