Java的条件:: agait()是否支持具有谓词/功能?
从java doc 1.8中,似乎条件只有等待()
,等待(long,timeunit)
,等待>等待>等待()
等
。 t具有一个看起来像条件的函数。await(() - > xxxxx)等待直到满足条件。 C ++ 11条件_Variable支持具有cv.Wait(Mutex,predicate_function)
,因此我们可以将lambda函数用作参数,以控制条件_variaile应从wait/等待返回时。
Java支持这一点吗?
From java doc 1.8, seems Condition only has await()
, await(long, TimeUnit)
, awaitNanos()
, etc.
It doesn't have a function that looks like Condition.await(()->xxxxx) to wait until a condition is met. c++11 condition_variable supports to have cv.wait(mutex, predicate_function)
so we can use a lambda function as a parameter to control when condition_variable should return from wait/await.
Does java support this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 docs ,c ++
prenti其生/代码>过载只是在通知通过时检查谓词,并且等同于
因此,我们可以在Java中简单地做同样的事情。
From the docs, the C++
condition_variable::wait
overload is just checking the predicate when a notification comes through and is equivalent toSo we can simply do the same thing in Java.