以显示当前系统中所有java进程
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NDc2Mzg5MjctYWI0ZTNhOTEtNDgzNy00YTQ5LTg1YjEtZGIzOWM3ODMxMTdjLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=474&margin=[object Object]&name=image.png&originHeight=474&originWidth=614&size=538905&status=done&style=none&width=614)
查看正在运行的Java程序的扩展参数
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NDc4MDA5ODQtODhiMDk0M2UtM2RhYy00MmNlLTlhY2ItMTE4MWY5MTcxNWQ0LnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=151&margin=[object Object]&name=image.png&originHeight=388&originWidth=1918&size=1146164&status=done&style=none&width=746)
等同于System.getProperties()
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NDc5NTU3MDQtMjI2YzFhMTUtYjc2ZC00Y2UyLTlkNzgtNzJmN2QxYWIwNWI4LnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=278&margin=[object Object]&name=image.png&originHeight=664&originWidth=1780&size=1904914&status=done&style=none&width=746)
jstat命令可以查看堆内存各部分的使用量,以及加载类的数量。命令格式:
jstat [-命令选项] [vmid] [间隔时间/毫秒] [查询次数]
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NDgwODM4ODYtMGEzZjVmZTctY2E0Yi00YThjLWFjNWItMDA2MzQ1NjcyMzk0LnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=193&margin=[object Object]&name=image.png&originHeight=193&originWidth=462&size=169423&status=done&style=none&width=462)
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NDgxNjE0NjAtZWFlY2U2M2YtYWI5OS00YjJhLTkwMjUtNWRjYjQ1YTZiYWE1LnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=199&margin=[object Object]&name=image.png&originHeight=199&originWidth=1340&size=478950&status=done&style=none&width=1340)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-3lQNXgmo-1589759922630)(https://cdn.nlark.com/yuque/0/2020/png/440247/1588648393408-1f50f937-d6c6-4766-8747-ff4d96039ba3.png#align=left&display=inline&height=200&margin=%5Bobject%20Object%5D&name=image.png&originHeight=200&originWidth=1583&size=546355&status=done&style=none&width=1583)]
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NDg1Njk0ODQtNmJhODE0MjgtOWI1Yy00MmQxLWJhOTEtNTg5MmMyNDVlZGZiLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=108&margin=[object Object]&name=image.png&originHeight=108&originWidth=822&size=167062&status=done&style=none&width=822)
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NDg3MTkyODEtNzlkYjkxNGUtYmI2Zi00NzM5LWE3M2MtNGUzOGEzMWFjNzRhLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=119&margin=[object Object]&name=image.png&originHeight=119&originWidth=1099&size=227595&status=done&style=none&width=1099)
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NDg4MTE0NTEtYThkNWFlMzctNjAyYS00Nzk3LTljMzItMTZlODdiZjEyYjQ5LnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=213&margin=[object Object]&name=image.png&originHeight=213&originWidth=927&size=360536&status=done&style=none&width=927)
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NDg4ODc2MzUtM2NjZDRkMTEtNjFmMi00NzEwLTkxYjUtZWZkNmY0OGFmNmNkLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=280&margin=[object Object]&name=image.png&originHeight=280&originWidth=833&size=447521&status=done&style=none&width=833)
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NDg5NjQ0MTEtNGZkNTIwZGUtZDFlZS00Y2ZlLTk4MzEtZTBjNWY3NzA0NjNkLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=155&margin=[object Object]&name=image.png&originHeight=155&originWidth=940&size=267667&status=done&style=none&width=940)
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NDkwMjk4NDAtNmEzMzczNTgtOTAwMy00ODQ3LWFhMmUtY2U4ZDViOTFmNjJlLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=235&margin=[object Object]&name=image.png&originHeight=235&originWidth=918&size=399949&status=done&style=none&width=918)
可以用来查看内存信息
**
jmap -histo 29420 > xxx.txt
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NDkzNDQ1NjItZTQ2YTE0OWItOGIxZS00NzQ1LTgyMDItNzRhMTg0ODQ0YzY1LnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=785&margin=[object Object]&name=image.png&originHeight=785&originWidth=1552&size=122390&status=done&style=none&width=1552)
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NDk0NTc0NjgtNzU3N2QyZjItZDA3ZS00MmFmLWI0OWEtN2FmNTZhZjNhYjg4LnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=783&margin=[object Object]&name=image.png&originHeight=783&originWidth=1046&size=1450586&status=done&style=none&width=1046)
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NDk1NzE3OTYtNWVjNjc5YjQtMGUwMi00NjMzLWEzOWMtMjBhODI4MmFiZDQwLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=151&margin=[object Object]&name=image.png&originHeight=151&originWidth=783&size=201101&status=done&style=none&width=783)
也可以在设置内存溢出的时候自动导出dump文件(内存很大的时候,可能会导不出来)
1.-XX:+HeapDumpOnOutOfMemoryError
2.-XX:HeapDumpPath=输出路径
-Xms10m -Xmx10m -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError - XX:HeapDumpPath=E:\java-learning\oomdump.dump
public class OutOfMemoryDump {
/**
* 设置JVM参数
* -Xms10m
* -Xmx10m
* -XX:+PrintGCDetails
* -XX:+HeapDumpOnOutOfMemoryError
* -XX:HeapDumpPath=路径
*/
public static void main(String[] args) {
//-Xms10m -Xmx10m -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=E:\java-learning
List<Object> list = new ArrayList<>();
int i = 0;
while(true){
list.add(new User(i++, UUID.randomUUID().toString()));
}
}
}
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NTAwMzA0ODQtMzNiMWY2OGUtMDYwOC00ZjFlLTlkMGYtY2FkNjhjNGJkMzRmLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=307&margin=[object Object]&name=image.png&originHeight=307&originWidth=1006&size=542486&status=done&style=none&width=1006)
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NTA2MTE2MTktMjMxNzkyYmQtOWY0My00MTNhLWIwZDUtMThkYjI3MDQ1ZDY1LnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=344&margin=[object Object]&name=image.png&originHeight=344&originWidth=801&size=28916&status=done&style=none&width=801)
可以使用jvisualvm命令工具导入文件分析
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NTAzNDMwMzYtNjliMDRhMGEtNjNmMi00NTM5LWEwMzYtYzUxNTI1ZGIwNWI5LnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=1013&margin=[object Object]&name=image.png&originHeight=1013&originWidth=1936&size=173396&status=done&style=none&width=1936)
jstack用于生成java虚拟机当前时刻的线程快照
![image.png](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9jZG4ubmxhcmsuY29tL3l1cXVlLzAvMjAyMC9wbmcvNDQwMjQ3LzE1ODg2NTA4MDA4MzktY2Q5Mjk0YjYtOTMyYy00ZDZmLTgxOTQtYzI4NGE2YWM2ODljLnBuZw?x-oss-process=image/format,png#align=left&display=inline&height=431&margin=[object Object]&name=image.png&originHeight=431&originWidth=970&size=64407&status=done&style=none&width=970)