4

We have a junit test runner which timeout if one test is hanging. Now I want create a thread dump via API.

I know I can request the stacktraces via Thread.getAllStackTraces(). But the thread dump on the console include many more information like the monitor which a thread is waiting.

Are there an API to request the monitor on which a thread is waiting?

Horcrux7
  • 23,758
  • 21
  • 98
  • 156

2 Answers2

3

You could use JMX to create a thread dump.

See How do I create a thread dump via JMX? for an example. The ThreadInfo class supports getting the locked monitors.

Community
  • 1
  • 1
Mark
  • 28,783
  • 8
  • 63
  • 92
1

JDK 6 documentation contains a section on programmatic monitoring of the JVM MBeans . I have never used them and would not be able to provide you sample code but it will definately give you a start.

Managing and monitoring programmatic way

The Attach API to connect to a remote JVM

I hope it helps , It will be very helpful if you can share the outcome of your research.

Anupam Saini
  • 2,431
  • 2
  • 23
  • 30