gpt4 book ai didi

java - java 对象中的等待池表示

转载 作者:行者123 更新时间:2023-12-01 10:21:17 27 4
gpt4 key购买 nike

我听说对对象使用synchronized关键字会创建一个等待池,其中存储与该对象关联的等待线程。它在内存中是如何表示的?

最佳答案

您可以查看关于 Intrinsic Locks and Synchronization 的 Java 文档

Every object has an intrinsic lock associated with it. By convention, a thread that needs exclusive and consistent access to an object's fields has to acquire the object's intrinsic lock before accessing them, and then release the intrinsic lock when it's done with them. A thread is said to own the intrinsic lock between the time it has acquired the lock and released the lock. As long as a thread owns an intrinsic lock, no other thread can acquire the same lock. The other thread will block when it attempts to acquire the lock.

enter image description here

还有这个:

enter image description here

关于java - java 对象中的等待池表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35595655/

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