请求Java ThreadInfo的堆栈跟踪?

我有一个应用程序在java.lang.management.ThreadInfo对象上调用getStackTrace(),但调用生成的StackTraceElement数组是零长度.

检查Javadoc显示了这一点(强调我的):

public StackTraceElement[] getStackTrace()

Returns the stack trace of the thread associated with this ThreadInfo. If no stack trace was requested for this thread info, this method will return a zero-length array. If the returned array is of non-zero length then the first element of the array represents the top of the stack, which is the most recent method invocation in the sequence. The last element of the array represents the bottom of the stack, which is the least recent method invocation in the sequence.

如何为此线程信息请求堆栈跟踪?

最佳答案
你打电话给getThreadInfo()怎么样?

您是否指定了堆栈跟踪深度?

getThreadInfo(long id, int maxDepth)
Returns a thread info for a thread of the specified id, with stack
trace of a specified number of stack
trace elements.

转载注明原文:请求Java ThreadInfo的堆栈跟踪? - 代码日志