xiaofengshan

常用JVM查看信息命令

top 观察内存使用情况、CPU占用率,
top -Hp 进程ID 观察进程中的线程,哪个线程CPU和内存占比高,
jstack 进程ID 定位线程状况,重点关注:WAITING BLOCKED。

常用工具使用

  • jconsole 远程连接
    JDK自带界面 线上不使用,影响效率 略。
  • jvisualvm 远程连接
    JDK自带页面 线上不使用,影响效率 略。
  • arthas
    阿里巴巴出品,命令界面,不会影响效率。
    • 地址
      https://arthas.aliyun.com/doc/quick-start.html
    • 常用命令
      java -jar arthas-boot.jar 启动arthas,
      dashboard 展示当前进程的信息以及堆使用情况,会一直进行打印堆信息。
      jvm 观察jvm信息,
      thread 定位线程问题,
      jad 反编译。

案例

package com.yxkj.jvm.basic;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @program:FoundationStudy
 * @Author: zhuyang
 * @Date: 2022/01/30/14:34
 * @Description: GC分析
 */
public class FullGC_Problem {

    private static class CardInfo {
        BigDecimal price = new BigDecimal(0.0);
        String name = "张三";
        int age = 5;
        Date birthdate = new Date();

        public void m() {}
    }

    private static ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(50,
            new ThreadPoolExecutor.DiscardOldestPolicy());

    public static void main(String[] args) throws Exception {
        executor.setMaximumPoolSize(50);

        for (;;){
            modelFit();
            Thread.sleep(100);
        }
    }

    private static void modelFit(){
        List<CardInfo> taskList = getAllCardInfo();
        taskList.forEach(info -> {
            // do something
            executor.scheduleWithFixedDelay(() -> {
                //do sth with info
                info.m();

            }, 2, 3, TimeUnit.SECONDS);
        });
    }

    private static List<CardInfo> getAllCardInfo(){
        List<CardInfo> taskList = new ArrayList<>();

        for (int i = 0; i < 100; i++) {
            CardInfo ci = new CardInfo();
            taskList.add(ci);
        }

        return taskList;
    }

}
  • 编译命令
    javac D:\zs\FullGC_Problem.java
  • 启动命令
    java -Xms200m -Xmx200m -XX:+PrintGCDetails com.yxkj.jvm.basic.FullGC_Problem

日志分析

image

image

Gitee地址

https://gitee.com/zhuayng/foundation-study/blob/develop/JavaBasis/JVM/src/main/java/com/yxkj/jvm/basic/IndentityHashCode.java

分类:

技术点:

相关文章:

  • 2021-07-27
  • 2021-07-06
  • 2022-01-10
  • 2021-08-19
  • 2021-08-18
  • 2021-06-13
  • 2021-09-12
猜你喜欢
  • 2022-12-23
  • 2021-05-23
  • 2021-11-08
  • 2022-12-23
  • 2021-09-12
  • 2022-12-23
相关资源
相似解决方案