Requesting a stack trace for a Java ThreadInfo?

时光总嘲笑我的痴心妄想 提交于 2019-12-07 05:25:41

问题


I have an application that calls getStackTrace() on a java.lang.management.ThreadInfo object, but the StackTraceElement array produced by the invocation is zero length.

Inspecting the Javadoc shows this (emphasis mine):

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.

How do I request a stack trace for this thread info?


回答1:


How are you calling getThreadInfo()?

Are you specifying a stack trace depth?

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.



来源:https://stackoverflow.com/questions/4315753/requesting-a-stack-trace-for-a-java-threadinfo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!