I’m trying to write some Thread Management utility, and reading up on ThreadMXBean.
http://download.oracle.com/javase/6/docs/api/java/lang/management/ThreadMXBean.html#dumpAllThreads(boolean, boolean)
According to the doc, getThreadInfo(long[] ids, int maxDepth) “does not obtain the locked monitors and locked synchronizers of the threads”, however, those methods that allow you to specify true to obtain lock/monitor information do not seem to enable you to specify maxDepth.
Is there anything I can do to specify both whether or not to obtain monitor/lock info as well as stack depth?
Thanks in advance!
You can copy the toString() from ThreadInfo, but remove the stack depth limitation to give you this :
Then call this method for each ThreadInfo returned from ThreadMxBean.dumpAllThreads()
Here is a gist with a utility class that has this method along with some sonarlint cleanup: https://gist.github.com/nddipiazza/13edf47fae104c34dd0331704bcf04e9