JRE のみでスレッド ダンプを取得するには、同じ Java バージョンの JDK から tools.jar と attach.dll が必要です。これをどこかにインストールし、これらを jre にコピーします。同一バージョンでなければなりません!
システム アカウントで実行されているプロセスのダンプが必要な場合は、Windows sysinternals psexec.exe を使用してプロセスにアクセスできます。これを JRE ビンまたはパスのどこかにコピーします。
このバッチ ファイルは、複数のトレースを取得して簡単に比較できるように、スタック ダンプを日時ファイル名のファイルに書き込みます。
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