Requesting a stack trace for a Java ThreadInfo?
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?
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.