gpt4 book ai didi

Java 对象作为监视器澄清

转载 作者:行者123 更新时间:2023-12-02 06:39:11 27 4
gpt4 key购买 nike

我使用以下资源来获取 Java 监视器的摘要,

http://www.informit.com/store/concurrent-programming-in-java-design-principles-and-9780201310092

http://www.artima.com/insidejvm/ed2/threadsynch.html

以下是我对 Java 的理解的总结,

Monitor is an object that is awarded about Threads. That >means when saying in Java that all objects are monitors >that means each object has the trait of thread awareness.

Thread is an active object . And other objects are passive >but are aware about threads .Hence monitors! In other >words passive objects have been smartened.

Why call "monitor" , because it monitors itself ! From what ? >From active objects i.e Threads

What awareness a monitor has?

a)It knows what thread currently access it.{owner}

b)It knows what threads are waiting on it till a special condition > is met.{wait set}

c)It knows who are in the queue to enter to it{entry set}

So how could a thread become an objects owner , it has to >acquire that object's lock !

<小时/>

1 Object IS a lock or HAS a lock ?

2 Above a,b,c are part of the state of an object or keep tracked by the JVM ( keep a record and associate it to the Object ID etc.)?

最佳答案

Java 中的每个对象都有一个与其关联的监视器。监视器是一种本质上等同于可重入锁的构造;同一线程可以多次进入监视器,并且会计算进入次数并与退出进行匹配。

您关于“主动”和“被动”对象的结论没有多大意义。 (我并不是说他们错了;我只是说我无法理解你想说什么。)

The semantics of monitors in the JVM定义明确,但实现却没有,并且可以通过多种方式来实现监视器。 JVM 以 JVM 作者决定的某种方式跟踪 a/b/c 中的所有项目。由于大多数对象的监视器从未使用过,因此一种策略是拥有一个与堆分离的监视器表,其中包含一个带有对象的 JVM ID、当前监视器内的线程以及条目数。

关于Java 对象作为监视器澄清,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19335716/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com