From the Java API documentation:
Condition
factors out theObject
monitor methods (wait
,notify
andnotifyAll
) into distinct objects to give the effect of having multiple wait-sets per object, by combining them with the use of arbitrary Lock implementations. Where aLock
replaces the use ofsynchronized
methods and statements, aCondition
replaces the use of theObject
monitor methods.
The purpose of implementing the Condition
interface is to gain access to its more nuanced await
methods. Therefore,
calling the method Object.wait(...)
on a class implementing the Condition
interface is silly and confusing.
final Lock lock = new ReentrantLock(); final Condition notFull = lock.newCondition(); ... notFull.wait();
final Lock lock = new ReentrantLock(); final Condition notFull = lock.newCondition(); ... notFull.await();