I need to use a condition variable in my code. Looking up the android API, I saw that the package android.os contained ConditionVariable. But I also found Condition under java.util.concurrent.locks.
The two classes seem to be designed for the same purpose.
Condition.await() <-> ConditionVariable.block()
Condition.signal() <-> ConditionVariable.open()
Is there a difference I should be aware of?
As described in the docs you linked,
Conditioncan wake single Threads, instead of waking all waiting ones (signalvssignalAll).ConditionVariableis state-based and thus allows keeping the condition open (in contrast to releasing all waiting threads at a single time, it is possible to not block threads at all usingopenandclose).So you should use
ConditionifConditionVariableis not available there.ConditionVariable, as a single call tosignalAllis nicer to read thanopendirectly followed byclose.while you should use
ConditionVariableif