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

JavaMultithreadingJvm

Java Problem Overview


enter image description here

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

Java Solutions


Solution 1 - Java

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).

Solution 2 - Java

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

Solution 3 - Java

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."

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser84592View Question on Stackoverflow
Solution 1 - JavaJesperView Answer on Stackoverflow
Solution 2 - JavaGrooveekView Answer on Stackoverflow
Solution 3 - JavamogronalolView Answer on Stackoverflow