开发者

Wait on multiple Conditions in Java

I want a thre开发者_如何学JAVAad to wait until any of two Conditions are signaled. Is it possible?

Suppose the thread is handling incoming packets of data, while it's possible a user interrupts by changing some states.

One Condition is signaled when a packet has come, and the other is signaled when states have been changed.

I think it's inappropriate to use one Condition for both events, because that would cause a lot of unnecessary wakeups in other threads which are monitoring the states.


You can add a third condition that is signaled by both incoming packets and user state changes? I don't think it is possible to wait on multiple conditions.


Use a semaphore, with 2 permits, have your waiting item acquire those 2, and have your events release those permits, 1 at a time until 2 are back?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜