Java Java stack trace

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

The client has a JRE, but not a JDK.

I want to use JStack, but it is not installed, and we cannot install the JDK on the client machine. I also tried using the AdaptJ stack trace product from a Java Webstart session, but this did not work because we are deleting and getting an error that there was not a session that started the application with the specified PID.

Essentially, I want to install JStack without installing the JDK.

+5
source share
5 answers

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

+5

JDK , , , jstack. ( PATH JAVA_HOME). , , JRE, , . , JConsole, , , . , jstack .

, , . , jdigital Eddie - , java, , , .

+4
+2

jstack jps tools.jar JDK. , attach.dll jstack .

, tools.jar attach.dll JRE.

jstack , JDK ( Windows), .

  • tools.jar attach.dll JDK - . : c:\temp\jstack
  • bat script, JRE.

, bat jstack.bat:

set JRE=c:\jrefolder
"%JRE%\bin\java" -classpath "c:\temp\jstack\tools.jar" -Djava.library.path="c:\temp\jstack" sun.tools.jstack.JStack %*

jps jps.bat .

JRE = c:\jrefolder

"%JRE%\bin\java" -classpath "c:\temp\jstack\tools.jar" -Djava.library.path="c:\temp\jstack" sun.tools.jps.Jps %*

:

jstack.bat -l <pid>

, .

+2

To get a stream dump using only the JRE, you need tools.jar and attach.dll from the JDK of the same version of Java. Install it somewhere and copy them into jre. There must be an identical version!

If you need a dump of a process running under a system account, you can use sysinternals Windows psexec.exe to access the process. Copy this to a JRE box or somewhere along the way.

This batch file writes a dump of the stack to a file with the file name datetime, so you can easily and easily compare multiple traces.

Threads.bat

:: Creates a thread dump for the tomcat6.exe process 
:: saved in a timestamped filename and views it!
:: Jim Birch 20111128 rev 2015-10-12

::Required the following files to be placed in the jre/bin folder:
:: attach.dll  - From the Java JDK  (must be the same version)
:: tools.jar   - ditto
:: psexec.exe  - from Windows sysinternals

::cd to jre/bin
d:
cd \application\jre\bin

::build datetime filename
rem datetime from wmi.exe
for /f "tokens=2 delims==" %%I in ('wmic os get localdatetime /format:list') do set dt0=%%I
rem  datetime string as YYYY-MM-DD-hhmmss
set dt=%dt0:~0,4%-%dt0:~4,2%-%dt0:~6,2%-%dt0:~8,6%
set ff=td-%dt%.txt
echo filename: %ff%

::PID of the process by named exe, eg, tomcat6    
for /F "tokens=2" %%I in ('TASKLIST /NH /FI "IMAGENAME eq tomcat6.exe"' ) DO SET PID=%%I
echo pid: %PID%

::combine above with jstack command
psexec -s jstack.exe -l %PID%  >>  %ff%

:: view result
start %ff%

::insert pause to debug or timer to review script operation
::ping localhost -n 20 >nul
::pause
0
source

All Articles