aspose file tools*
The moose likes General Computing and the fly likes Heap and thread dump on Windows service Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "Heap and thread dump on Windows service" Watch "Heap and thread dump on Windows service" New topic
Author

Heap and thread dump on Windows service

Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5830
    
    7

I would like to take a heap dump and a thread dump of my Java app. Now I know how to do this if I run the Java app from a command line using java.exe. But my app is started as a Windows service using Apache's Proc Run. Thus, in one example, I have tomcat.exe running. I tried running VisualVM but it doesn't see tomcat.exe. I guess I have been so used to running things from the command line that I haven't looked into getting thread dumps or heap dumps in other environments. Anyone know what the best way to get such dumps would be?


JBoss In Action
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

I'm not sure it will work in your case, but I was able to do this for WebStart application which also doesn't display the text mode console: go to Java Control Panel and on the Advanced tab activate Java console/Show console. When the application starts, it should display a regular window (ie. not the text mode console) which will contain the JVM console output. There are several keys listed in the output when the console appears; pressing these keys initiates some actions, including Thread Dump. Not sure about Heap Dump, though.

This might not work if it really runs as a Windows service, with disabled desktop interaction.

On the other hand, I'd expect that tomcat will start the applications in separate processes, using java.exe (at least OAS does it this way). Don't you see any java.exe in VisualVM?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5830
    
    7

No, there is no java.exe in Task Manager. I have one process named tomcat6.exe*32, and another named container.exe*32 (yes, we are running 32-bit JVMs on a 64-bit system). I'll experiment with the Java Control Panel suggestion and see if that works (I can always enable desktop interaction on the service).
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5830
    
    7

I tried the Java Control Panel settings. Interestingly enough, I get a console for tomcat6.exe, but not for container.exe. Looking at Process Explorer, tomcat6.exe is using the JRE JVM, while container.exe is using the JDK JVM, that could explain the difference (they are both the same Java version). But I noticed two other processes with the JRE loaded, but no console showed up for them.

I tried using jmap to get a thread dump but Windows displays the message "Not enough storage is available to process this command." and none of the workarounds for this error that I found while googling have yielded any results (apparently there are multiple "storage" areas and I haven't found a web page that tells me how to increase the one I need).
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2377
    
  28

Have you tried running VisualVM as a service ?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5830
    
    7

Jayesh, that looks interesting, I'll have to give it a try.

Meanwhile one of my colleagues volunteered to look into running the service in debug mode and then remotely connecting VisualVM and was successful.

Oh, and I found out why only one of my services displayed a console - it was the only service for which I enabled desktop interaction!
 
Consider Paul's rocket mass heater.
 
subject: Heap and thread dump on Windows service