gpt4 book ai didi

java - 线程 - wait()

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:00:56 24 4
gpt4 key购买 nike

对象上的 wait() 方法只能在同步上下文中调用,即当前线程必须锁定对象才能调用 wait()方法。现在,如果线程 T1 锁定了对象 (obj) 并调用其等待方法 obj.wait() 。其他线程如何锁定这个对象 (obj) 以便它们也可以调用已经拥有 T1 的等待?

最佳答案

wait 释放同步上下文。来自documentation :

The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until another thread notifies threads waiting on this object's monitor to wake up (...)

关于java - 线程 - wait(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7380135/

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