Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait on multiple Conditions in Java

I want a thread 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.

like image 945
niboshi Avatar asked Aug 31 '25 22:08

niboshi


1 Answers

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.

like image 67
sbridges Avatar answered Sep 04 '25 00:09

sbridges