zoukankan      html  css  js  c++  java
  • JVM-问题定位示例

    内存溢出定位与分析

    1. 模拟内存溢出,向集合中添加极大数量的字符串

    package com.example.testcpu;
    
    import java.util.ArrayList;
    import java.util.List;
    import java.util.UUID;
    
    public class TestJvmOutOfMemory {
    
        public static void main(String[] args) {
            List<Object> list = new ArrayList<>();
            for (int i = 0; i < 10000000; i++) {
                String str = "";
                for (int j = 0; j < 1000; j++) {
                    str += UUID.randomUUID().toString();
                }
                list.add(str);
            }
            System.out.println("ok");
        }
    }

    2. 运行参数:

    -Xms8m -Xmx8m -XX:+HeapDumpOnOutOfMemoryError

    结果:

    objc[78198]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java (0x103bf64c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x103c7a4e0). One of the two will be used. Which one is undefined.
    java.lang.OutOfMemoryError: Java heap space
    Dumping heap to java_pid78198.hprof ...
    Heap dump file created [7918632 bytes in 0.055 secs]
    Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
        at java.util.Arrays.copyOf(Arrays.java:3332)
        at java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:137)
        at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:121)
        at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:421)
        at java.lang.StringBuilder.append(StringBuilder.java:136)
        at com.example.testcpu.TestJvmOutOfMemory.main(TestJvmOutOfMemory.java:14)
    
    Process finished with exit code 1

    定位死锁问题

    将dump文件导入到MAT中分析

    发现服务器的CPU的负载突然增

    高了、出现了死锁、死循环等,我们该如何分析呢?

    1. 找到CPU占比高的进程

    2. jstack查看线程情况,如发生死锁,会在最下面显示

  • 相关阅读:
    Proj THUDBFuzz Paper Reading: The Art, Science, and Engineering of Fuzzing: A Survey
    Proj THUDBFuzz Paper Reading: A systematic review of fuzzing based on machine learning techniques
    9.3 付费代理的使用
    11.1 Charles 的使用
    第十一章 APP 的爬取
    10.2 Cookies 池的搭建
    10.1 模拟登录并爬取 GitHub
    11.5 Appium 爬取微信朋友圈
    11.4 Appium 的基本使用
    11.3 mitmdump 爬取 “得到” App 电子书信息
  • 原文地址:https://www.cnblogs.com/yintingting/p/8893775.html
Copyright © 2011-2022 走看看