Javacore和Heapdump生成和获取

在这里插入图片描述

Javacore和Heapdump生成和获取

JavaCore和HeapDump文件

JavaCore

又称为ThreadDump,保存的是Java应用各线程在某一时刻的运行的位置,即JVM执行到哪一个类、哪一个方法、哪一个行上。
它是一个文本文件,打开后可以看到每一个线程的执行栈,以stack trace的显示。
通过对ThreadDump文件的分析可以得到应用是否“卡”在某一线程上,即在某一线程运行的时间太长。

HeapDump

二进制文件,它保存了某一时刻JVM堆中对象使用情况。
作用就是分析系统中是否存在内存溢出的情况。

JavaCore(ThreadDump)生成方法

方法1: Getting a Thread Dump Using jstack

In JDK 1.6 and higher, it is possible to get a thread dump on MS Windows using jstack.
Use PID via jps to check the PID of the currently running Java application process.
Use the extracted PID as the parameter of jstack to obtain a thread dump.

方法2: A Thread Dump Using jVisualVM

Generate a thread dump by using a program such as jVisualVM.
The task on the left indicates the list of currently running processes.
Click on the process for which you want the information,
and select the thread tab to check the thread information in real time.
Click the Thread Dump button on the top right corner to get the thread dump file.

方法3:Generating in a Linux Terminal

Obtain the process pid by using ps -ef command to check the pid of the
currently running Java process.
Use the extracted pid as the parameter of kill –SIGQUIT(3) to obtain a thread dump.

例如:

# 查询进程
# ps -ef | grep java  
user 3186 5872 0 18:40 pts/0 00:00:00 grep java  
root 7760 1 0 Oct27 ? 00:02:27 /usr/bin/java -server -XX:PermSize=64M -XX:MaxPermSize=128m  -classpath :/usr/local/tomcat8090/bin/bootstrap.jar  org.apache.catalina.startup.Bootstrap start  
# 执行kill命令
# kill -3 7760

ThreadDump文件格式

2018-10-09 11:27:02
Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.80-b11 mixed mode):
 
"elasticsearch[Norman Osborn][management][T#2]" daemon prio=6 tid=0x0000000020d7f800 nid=0x434 waiting on condition [0x000000003446e000]
   java.lang.Thread.State: TIMED_WAITING (parking)
	at sun.misc.Unsafe.park(Native Method)
	- parking to wait for  <0x00000000ca2f0828> (a org.elasticsearch.common.util.concurrent.EsExecutors$ExecutorScalingQueue)
	at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226)
	at java.util.concurrent.LinkedTransferQueue.awaitMatch(LinkedTransferQueue.java:731)
	at java.util.concurrent.LinkedTransferQueue.xfer(LinkedTransferQueue.java:644)
	at java.util.concurrent.LinkedTransferQueue.poll(LinkedTransferQueue.java:1145)
	at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1068)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:745)
 
   Locked ownable synchronizers:
	- None
 
"VM Thread" prio=10 tid=0x00000000099db000 nid=0xe64 runnable 
 
"GC task thread#0 (ParallelGC)" prio=6 tid=0x00000000025ce000 nid=0x1c18 runnable 
 
"GC task thread#1 (ParallelGC)" prio=6 tid=0x00000000025cf800 nid=0x10cc runnable 
 
"GC task thread#2 (ParallelGC)" prio=6 tid=0x00000000025d1800 nid=0xbcc runnable 
 
"GC task thread#3 (ParallelGC)" prio=6 tid=0x00000000025d3000 nid=0x1ee4 runnable 
 
"VM Periodic Task Thread" prio=10 tid=0x000000000b26b000 nid=0x194c waiting on condition 
 
JNI global references: 46038

HeapDump 生成方式

方法1:Using jVisualVM

方法2:jvm参数

-XX:+HeapDumpOnOutOfMemoryError 
-XX:HeapDumpPath=/log/

利用jvisualvm生成Threaddump(Javacore)和Heapdump

jvisualvm 在jdk目录中

img

启动 jvisualvm

img

选择1个java程序双击

img

点击 线程 dump ,生成Threaddump文件,查看生成文件路径

img

点击堆 Dump,生成 Heapdump 文件

img

获取Heapdump文件路径

img

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不 古

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值