使用以下批处理文件获取在Windows控制台shell中运行的Java服务的核心转储时出现此错误:
The parent directory name of this script is: MyDIR
Install dir is: C::\InstallDIR
The process id of window called MyDIR is 520
Taking core dump... please wait...
C::\InstallDIR\Javasoft\bin\jmap.exe -dump:file=heap.bin 520
Dumping heap to C:\InstallDIR\MyDIR\heap.bin ...
Exception in thread "main" java.lang.InternalError: Remote thread failed for
unknown reason
at sun.tools.attach.WindowsVirtualMachine.enqueue(Native Method)
at sun.tools.attach.WindowsVirtualMachine.execute(WindowsVirtualMachine.java:78)
at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:195)
at sun.tools.attach.HotSpotVirtualMachine.dumpHeap(HotSpotVirtualMachine.java:162)
at sun.tools.jmap.JMap.dump(JMap.java:224)
at sun.tools.jmap.JMap.main(JMap.java:122)
Press any key to continue . . .
这是脚本(-XX:OnError =“script.bat”):
@echo off
setlocal
set PATH=%PATH%;C:\InstallDIR\Javasoft\jre\bin\server
for /F "tokens=2,3,4,5,6,7 delims=\" %%i in ('cd') do (
set i=%%i
set j=%%j
set k=%%k
set l=%%l
set m=%%m
set n=%%n
)
set HOME=%i%
if not "%i%" == "" (set SITE=%i%
) else (goto end:)
if not "%j%" == "" (set SITE=%j%
) else (goto end:)
if not "%k%" == "" (set SITE=%k%
) else (goto end:)
if not "%l%" == "" (set SITE=%l%
) else (goto end:)
if not "%m%" == "" (set SITE=%m%
) else (goto end:)
if not "%n%" == "" (set SITE=%n%
) else (goto end:)
:end
echo The parent directory name of this script is: %SITE%
echo Install dir is: %HOMEDRIVE%:\%HOME%
echo.
:: kill process using window TITLE to find PID
FOR /F "tokens=2" %%I in ('TASKLIST /NH /FI "WINDOWTITLE eq %SITE%"' ) DO SET PID=%%I
ECHO The process id of window called %SITE% is %PID%
ECHO Taking core dump... please wait...
%HOMEDRIVE%\%HOME%\Javasoft\bin\jmap.exe -dump:format=b,file=heap.bin %PID%
ECHO Killing JVM %PID%...
TASKKILL /PID %PID%
:: then , restart server
.\startServer.bat
ping -n 12 127.0.0.1>nul
if ERRORLEVEL == 0 (
exit
) else (
pause
)
我可以运行jconsole.exe,附加到进程并轻松转储核心。为什么命令行不容易?我知道JMap的linux版本有更多选项和功能。这就是我在这里遇到的情况:JMap的Windows版本无法做到这一点的情况吗?
答案 0 :(得分:0)
为致命 jvm错误调用-XX:OnError处理程序。当发生这种情况时,您可能无法启动新线程来转储堆。 (这就是jmap的作用。)
然而,你可以通过传递来完成你想要的 -X:+ HeapDumpOnOutOfMemoryError 和 的 -XX:HeapDumpPath = 路径 强>