As described in the docs you linked, Condition
can wake single Threads, instead of waking all waiting ones (signal
vs signalAll
).
ConditionVariable
is 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 using open
and close
).
So you should use Condition
if
- you need to be compatible to regular Java (for example in a Library used for a PC/Server/whatever application, too), as
ConditionVariable
is not available there. - you need to wake single threads
- (my personal opinion) you're not needing the open phase of
ConditionVariable
, as a single call tosignalAll
is nicer to read thanopen
directly followed byclose
.
while you should use ConditionVariable
if
- you have phases within your application where you do not need any blocking at all