tags:

views:

1485

answers:

4

I need to get a stack trace for a JVM process running on a client machine that uses windows.

The client has the JRE installed but not the JDK.

I want to use JStack but it is not installed and we can't install a JDK on the client's machine. I also tried using AdaptJ stack trace product from a Java Webstart Session but that didn't work because we remote in and get an error about not being the session that started the application at a specified PID.

Essentially I want a way to install JStack without installing the JDK.

+2  A: 

You probably want to use SendSignal, which was designed for exactly this purpose.

Eddie
From looking at the SendSignal webpage, I would be careful if the app is being run as a service (or otherwise has -Xrs (reduce signal usage)) as an argument. If so, Java's ctrl+break handling is disabled and the application will terminate when it receives this signal.
Joshua McKinnon
Actually, I use SendSignal.exe for this purpose to cause a stackdump of a JRE running as a service. It works for me.
Eddie
Yes, if someone runs "java -Xrs ..." then perhaps they'll have a problem with SendSignal.exe. The solution is that you can't do both at the same time. Choose one. Either use -Xrs or use SendSignal.exe to cause a stackdump. Your choice.
Eddie
I tried a test with SendSignal where my java process was running in a open console window and it worked, i saw an error in the console window. But when a jvm process is running in the background where can i get the print out of the stack trace.
richs
The stack trace goes to wherever standard output of the process goes. Ideally, this goes to a log file somewhere.
Eddie
+1  A: 

Would you be able to use JConsole via remote access?

jdigital
+1 jvisualvm is also handy
Bob Cross
+1  A: 

The JDK and associated tools work fine whether "installed" or not, if you just zip up and extract it to a temporary directory, you should be able to run jstack. (No PATH or JAVA_HOME modifications necessary). Just make sure you use the same version that corresponds to the JRE your client has the application running with. At least in the case of JConsole, it seems to fuss if the versions are different. I'm not sure if jstack behaves the same way.

I'm not saying this is the ideal solution, just that it would work. I think jdigital and Eddie's suggestions are better first bets, and even though this shouldn't interfere with an existing java installation the same way running the installer would, the customer may disagree regardless.

Joshua McKinnon
A: 

All the tools on your list (jstack, SendSignal, AdaptJ StackTrace) have the same limitation. You can not run them in a different session from your target process. The easiest option is to download psexec from Microsoft and try to run them like this (assuming you are in session 1):

  • SendSignal

psexec.exe -i 0 -d SendSignal.exe [pid]

The dump will go to the standard output of the target process.

  • AdaptJ StackTrace the standalone version. Create a bat file c:\temp\run_it.bat containing the following line:

"C:\Program Files\StackTrace\stacktrace.war\bin\jstack.exe" %1 > C:\temp\dump.txt

psexec.exe -i 0 -d c:\temp\run_it.bat [pid]

The output will go to C:\temp\dump.txt

StackTrace also has a service and a web application (webapp_start.bat) which can be started in any session so there is no need for psexec.

  • JDK jstack - same as AdaptJ StackTrace

The -d argument for psexec is optional. There may be problems with processes running in session different than 0.

Todor