Rapid printing of JSTACK and JSTAT
At work, sometimes the JBoss server is on the machine and you need to use the command line to obtain the JSTACK and JSTAT logs for analysis of the cause. However, to obtain the preceding logs, You need to first query the process number, which is basically not allowed due to time issues in production.
Therefore, a batch processing command is written to complete this action.
Restrictions:
Only one java.exe process is running
You must add the java_home \ bin directory to the path environment variable.
@echo off&setlocal enabledelayedexpansionREM ======================set /a cnt=10REM ======================set /a j=0,k=16*1024*1024,p=0set dt=%date:~,4%%date:~5,2%%date:~8,2%%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%for /f "skip=1 tokens=1-2 delims= " %%a in ('wmic process where "name='java.exe'" get WorkingSetSize^,Handle') do ( if %%b LSS !k! ( REM echo "%%b less than %k%" ) else ( set /a p=%%a set /a j=j+1 ))if %p% EQU 0 ( echo Cannot find Java Process memory use greater than 16M.) else if NOT %j% EQU 1 ( echo Find too more Java Process, cannot determine which one.) else ( echo Saving JBoss thread status to c:... jstack -l %p% > "C:\JSTACK_%dt%.log" echo Saving JBoss memory status to c:... jstat -gc -t %p% 2000 %cnt% > "C:\JSTAT_%dt%.log")echo Finished!pause