org.sonar.l10n.java.rules.squid.S1844.html Maven / Gradle / Ivy
The newest version!
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
final Lock lock = new ReentrantLock();
final Condition notFull = lock.newCondition();
...
notFull.wait();
Compliant Solution
final Lock lock = new ReentrantLock();
final Condition notFull = lock.newCondition();
...
notFull.await();
© 2015 - 2025 Weber Informatics LLC | Privacy Policy