简体   繁体   English

Java JVM概要分析,线程状态 - “监控”状态意味着什么?

[英]Java JVM profiling, thread status - what does “Monitor” status mean?

在此输入图像描述

I use visualVM connect a multi thread Java application, thread has 4 status, namely running, sleeping, wait, Monitor. 我使用visualVM连接一个多线程Java应用程序,线程有4个状态,即运行,休眠,等待,监视。 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. 这些状态与Thread.State枚举中提到的相同。 "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 Object.wait没有超时
  • Thread.join with no timeout Thread.join没有超时
  • LockSupport.park 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). “Monitor”是BLOCKED状态,其中线程正在等待获取对象的锁定(因为它试图进入synchronized块或方法,而另一个线程已经拥有相关的锁)。

That's not a "monitoring" status... It indicates that the thread is in the Thread.State.BLOCKED state. 这不是“监视”状态...它表示该线程处于Thread.State.BLOCKED状态。 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. 例如,当一个线程正在运行一个synchronized方法而另一个线程试图在同一个对象上调用它时,它将无法在方法的第一次调用完成之后。 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 : 来自Oracle线程教程

"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." “同步是围绕一个称为内部锁或监视器锁的内部实体构建的。(API规范通常将此实体简称为”监视器“。)内部锁在同步的两个方面都发挥作用:强制执行对同步的独占访问。对象的状态和建立事先发生的关系,这对于可见性至关重要。“

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM