如何获取正在运行的应用程序的Java Call Stack [英] How to get Java Call Stack of a running application

查看:112
本文介绍了如何获取正在运行的应用程序的Java Call Stack的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究非常巨大的基于java网络的应用程序。由于在开发过程中没有正确的日志记录,所以我很难把断点和调试应用程序,因为我不知道执行顺序。在执行一些操作后,是否有任何机制来获取运行中的Java应用程序的完整调用堆栈。



我在网上搜索了很长时间,但无法得到具体的解决方案。请给我建议,如果有东西在那里。谢谢

解决方案

方法1:使用命令行中的jstack实用程序(JDK发行版的一部分)。



方法2:将信号3发送到java进程,它将在stdout上转储堆栈跟踪。



方法3:调用Thread.getAllStackTraces )从应用程序中:

  public class StackTraceDumper 
{
public static dumpAllStackTraces()
{
for(Map.Entry&Thread; StackTraceElement []>条目:
Thread.getAllStackTraces()。entrySet())
{
System.out.println entry.getKey().getName()+:);
(StackTraceElement element:entry.getValue())
System.out.println(\t+ element);
}
}
}

然后使用 StackTraceDumper.dumpAllStackTraces()您需要转储堆栈跟踪。


I am working on very huge java web based application. As there is no proper logging done while development so its very difficult for me to put break point and debug the app as i dont know execution order. Is there any mechanism to get complete Call Stack of the the running java application after I perform some actions.

I searched it on net for long time but cannot came to concrete solution. Please suggest me if something is there for it. Thanks

解决方案

Method 1: Use jstack utility from command line (part of the JDK distro).

Method 2: Send signal 3 to the java process, it will dump stack traces on stdout.

Method 3: Call Thread.getAllStackTraces () from within application:

public class StackTraceDumper
{
    public static dumpAllStackTraces ()
    {
        for (Map.Entry <Thread, StackTraceElement []> entry: 
            Thread.getAllStackTraces().entrySet ())
        {
            System.out.println (entry.getKey ().getName () + ":");
            for (StackTraceElement element: entry.getValue ())
                System.out.println ("\t" + element);
        }
    }
}

Then use StackTraceDumper.dumpAllStackTraces() where you need to dump stack traces.

这篇关于如何获取正在运行的应用程序的Java Call Stack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆