Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

java - Is a JVM stopped while executing jmap?

Does my java application continue running while jmap is taking its memory dump?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had an issue with trying to do this on a production machine creating the hprof file with jmap took ages and naturally locked up the java webapp for ages.

I found this page:

http://blogs.atlassian.com/2013/03/so-you-want-your-jvms-heap/

Which explained that you can also use gdb (on linux systems) to dump the core of the java process.

With this core file you can then generate the hprof file for analysis in a separate process which prevent your java server process from being interrupted for such a long time. Which is what would happen if you were to run the same operation with jmap.

To summarise:

download and install gdb

apt-get update

apt-get install gdb

...

get the java process id of the java process you're interested in

jps ...

start a gdb session with that process

gdb [pid] ...

then generate the core file:

gcore /tmp/jvm.core

end the gdb session

detach quit

then use the core file generated to make an hprof file:

sudo jmap -dump:format=b,file=jvm.hprof /usr/bin/java /tmp/jvm.core

then (g)zip the file up and copy it to your machine for further analysis.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...