有没有办法转储堆栈跟踪而不在java中抛出异常? [英] Is there a way to dump a stack trace without throwing an exception in java?

查看:25
本文介绍了有没有办法转储堆栈跟踪而不在java中抛出异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑为我的 Java 应用程序创建一个调试工具.

I am thinking of creating a debug tool for my Java application.

我想知道是否有可能获得堆栈跟踪,就像 Exception.printStackTrace() 但实际上不抛出异常?

I am wondering if it is possible to get a stack trace, just like Exception.printStackTrace() but without actually throwing an exception?

我的目标是,在任何给定的方法中,转储一个堆栈以查看方法调用者是谁.

My goal is to, in any given method, dump a stack to see who the method caller is.

推荐答案

您还可以尝试 Thread.getAllStackTraces() 来获取所有活动线程的堆栈跟踪图.

You can also try Thread.getAllStackTraces() to get a map of stack traces for all the threads that are alive.​​​​​​

这篇关于有没有办法转储堆栈跟踪而不在java中抛出异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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