开发者

Java JVM profiling, thread status - what does "Monitor" status mean?

Java JVM profiling, thread status - what does "Monitor" status mean?

I use visualVM connect a multi thread Java application, thread has 4 status, 开发者_Go百科namely running, sleeping, wait, Monitor. What does this Monitoring status mean? What's the difference between wait and Monitor?


These states are the same as mentioned in the Thread.State enum. "Wait" means, as the documentation says:

A thread is in the waiting state due to calling one of the following methods:

  • Object.wait with no timeout
  • Thread.join with no timeout
  • LockSupport.park

"Monitor" is the BLOCKED state, in which the thread is waiting to obtain a lock on an object (because it's trying to enter a synchronized block or method while another thread already holds the associated lock).


That's not a "monitoring" status... It indicates that the thread is in the Thread.State.BLOCKED state. I see there is another good answer, i'll just point you to this link for deeper explanation


Monitor will mean the thread is waiting to attain a lock on an object. For example when one thread is running a synchronized method and another one tries to invoke it on the same object, it will not be able to until the first invocation of the method is finished. This is because the first thread has a monitor or lock on that object, so the second one must wait until it is released.

From Oracle Threading Tutorials:

"Synchronization is built around an internal entity known as the intrinsic lock or monitor lock. (The API specification often refers to this entity simply as a "monitor.") Intrinsic locks play a role in both aspects of synchronization: enforcing exclusive access to an object's state and establishing happens-before relationships that are essential to visibility."

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜