How to find out which monitor is a thread waiting through the API?

We have a junit test runner, timeout if one test hangs. Now I want to dump the stream through the API.

I know that I can request stacktraces through Thread.getAllStackTraces (). But a dump of the stream on the console includes much more information, such as a monitor that is waiting for the stream.

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

+4
source share
2 answers

You can use JMX to dump the stream.

See How to dump a stream through JMX? for example. The ThreadInfo class supports getting locked monitors.

+3
source

The JDK 6 documentation contains a section on monitoring software MBeans JVM. I never used them and could not provide you with sample code, but it will definitely give you a start.

Software Management and Monitoring

Bind API to connect to remote JVM

I hope this helps, it will be very useful if you can share the results of your research.

+1
source

All Articles