41 lines
1.2 KiB
Plaintext
41 lines
1.2 KiB
Plaintext
From the Java API documentation:
|
|
|
|
____
|
|
``++Condition++`` factors out the ``++Object++`` monitor methods (``++wait++``, ``++notify++`` and ``++notifyAll++``) 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 a ``++Lock++`` replaces the use of ``++synchronized++`` methods and statements, a ``++Condition++`` replaces the use of the ``++Object++`` 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.
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
[source,java]
|
|
----
|
|
final Lock lock = new ReentrantLock();
|
|
final Condition notFull = lock.newCondition();
|
|
...
|
|
notFull.wait();
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
[source,java]
|
|
----
|
|
final Lock lock = new ReentrantLock();
|
|
final Condition notFull = lock.newCondition();
|
|
...
|
|
notFull.await();
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|