jstack命令执行报错:Unable to open socket file: target process not responding or HotSpot VM not loaded

一、背景

最近在学jvm调优,在使用jstack命令时,出现报错。网上查了好多,都没有找到合适解决方法。

二、解决方法

1.测试代码

public class T15_FullGC_Problem01 {

    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;
    }
}

2.在linux下启动程序

java -Xms200M -Xmx200M -XX:+PrintGC T15_FullGC_Problem01

3.通过top命令查看占用cpu和内存比价搞的进程

4.通过top -Hp命令查看进程中的线程,找出线程占用资源比较多的线程

5.通过jstack命令,查看详细信息

6.在第5步是,报错了

分析之后发现,需要将线程中的线程号转换为十六进制才行,起始jstack可以直接查询进程的进程号信息。

jstack直接加进程号是可以直接使用的

 

小编也有自己微信公众号:“JAVA菜鸟程序猿”,喜欢的可以关注下哦!

评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

JAVA菜鸟程序员

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

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

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

打赏作者

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

抵扣说明:

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

余额充值