确定当前调用堆栈(用于诊断目的) [英] Determining Current Call Stack (For Diagnostic Purposes)

查看:116
本文介绍了确定当前调用堆栈(用于诊断目的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于诊断目的,我有时需要存储导致给定状态转换的调用堆栈(例如授予锁定,提交事务等),以便以后出现问题时我可以找出最初触发的是谁状态转换。

For diagnostic purposes I sometimes need to store the call stack that lead to a given state transition (such as granting a lock, committing a transaction, etc.) so that when something goes wrong later I can find out who originally triggered the state transition.

目前,我知道检索调用堆栈的唯一方法类似于以下代码片段,我认为这非常难看:

Currently, the only way I am aware of to retrieve the call stack looks like the following code snippet, which I consider terribly ugly:

StackTraceElement[] cause;
try {
  throw new Exception();
} catch (Exception e) {
  cause = e.getStackTrace();
}

有人知道更好的方法吗?

Does somebody know of a better way to accomplish this?

推荐答案

我认为你可以得到同样的东西:

I think you can get the same thing with:

StackTraceElement[] cause = Thread.currentThread().getStackTrace();

这篇关于确定当前调用堆栈(用于诊断目的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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