How to see what monitor is a thread waiting for?
So, my question is: is there a way to understand what monitor a thread is waiting for?
Thank you
First try to take a thread dump when waiting on a monitor occurs. There are various ways of doing that, including jstack
, jvisualvm and kill -3
. Also Netbeans might be able to do this for an application that it executed.
Having thread-dump file import it in tda. Although You discover a lot just by reading the file in plain text editor, this simple application groups threads and monitors, allows you to browse threads including hyper-links, etc. Look pretty obscure, but works well.
If You'll have difficulties reading stack-traces (this is a very important skill for Java developers), post one waiting thread here.
It sounds like you have written your program not to need synchronization and what you really why to know is where in the code it is that it need synchronization ratehr than which objects it is locking on. To find where in the code it is, look at the thread dump. Jconsole/jstack can do this.
精彩评论