开发者

How to see what monitor is a thread waiting for?

I'm using netbeans and it's profiler to look at threads activity. The graphs shows that when there is more than a working thread executin开发者_StackOverflow社区g, the threads can stay in a number of states: running, waiting, monitor.

I wrote my java application so that its working threads should use only read-only variables without synchronization needs.

However, when executing netbeans profiler, I can see that often my threads are in monitor state. I suppose that they're waiting for a monitor to unlock, but I can imagine which monitor.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜