线程-wait() [英] Threading - wait()

查看:65
本文介绍了线程-wait()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The wait() method on an object can be called only in the synchronized context i.e. the current thread must have a lock on the object to invoke the wait() method. Now if a thread T1 has a lock on an object(obj) and invokes its wait method obj.wait() . How can other threads get lock on this object(obj) so that they can also call wait, which is already possessed T1 ?

推荐答案

wait释放同步的上下文.从文档:

wait releases the synchronized context. From the 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 (...)

这篇关于线程-wait()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆