Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在使用trace命令的时候,对于方法里面有sleep操作的方法无法显示调用信息,日志也没有报错 #2806

Open
1 task done
andyyu086 opened this issue Feb 29, 2024 · 1 comment

Comments

@andyyu086
Copy link

andyyu086 commented Feb 29, 2024

  • 我已经在 issues 里搜索,没有重复的issue。

环境信息

  • arthas-boot.jar 或者 as.sh 的版本: 3.7.2
  • Arthas 版本: 3.7.2
  • 操作系统版本: macOS 10.13.6 (Darwin Kernel Version 17.7.0)
  • 目标进程的JVM版本: jdk1.8.0_162
  • 执行arthas-boot的版本: 3.7.2

重现问题的步骤

  1. 运行如下代码:
package com.mvp.service;


import java.util.concurrent.TimeUnit;

public class HqlParseMain {

    public static void main(String[] args) throws InterruptedException {
        String input ="SELECT ";
        HqlParseMain parseTest = new HqlParseMain();

        parseTest.doParse2(input);
    }

    private void doParse2(String input) throws InterruptedException {
        while (true) {
            System.out.println(input);
            sleep();
        }
    }

    private void sleep() throws InterruptedException {
        TimeUnit.SECONDS.sleep(2);
    }
}

输入trace命令,查看结果一直没有出现:
[arthas@17951]$ trace com.mvp.service.HqlParseMain doParse2
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 1) cost in 98 ms, listenerId: 1
一直等待不会出现调用结果的。

  1. 代码改成:
package com.mvp.service;


import java.util.concurrent.TimeUnit;

public class HqlParseMain {

    public static void main(String[] args) throws InterruptedException {
        String input ="SELECT ";
        HqlParseMain parseTest = new HqlParseMain();

        while (true) {
            parseTest.doParse2(input);
            parseTest.sleep();
        }
    }

    private void doParse2(String input) throws InterruptedException {
        for (int i = 0; i < 100; i++) {
            System.out.println(input);
        }
    }

    private void sleep() throws InterruptedException {
        TimeUnit.SECONDS.sleep(2);
    }
}

输入trace命令就会正常出现结果:

[arthas@17842]$ trace com.mvp.service.HqlParseMain doParse2
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 1) cost in 95 ms, listenerId: 1
---ts=2024-02-29 17:36:43;thread_name=main;id=1;is_daemon=false;priority=5;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2 ---[2.426401ms] com.mvp.service.HqlParseMain:doParse2()

期望的结果

第1步的方法也可以查看到调用信息。

实际运行的结果

参考上文的结果描述。

在日志没有发现异常,感觉问题应该跟java.lang.Thread有关。
@sirius19
Copy link

sirius19 commented Mar 4, 2024

trace命令执行之后,没有出现doParse2方法的调用,所以就看不到调用信息

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants