org.sonar.l10n.java.rules.squid.S2236.html Maven / Gradle / Ivy
The newest version!
On a Thread instance, the methods wait(...)
, notify()
and notifyAll()
are available only because all classes in Java extend Object
and therefore automatically inherit the methods. But there are two very good reasons to not call these methods on a Thread instance:
- Doing so is really confusing. What is really expected when calling, for instance, the
wait(...)
method on a Thread? That the execution of the Thread is suspended, or that acquisition of the object monitor is waited for?
- Internally, the JVM relies on these methods to change the state of the Thread (
BLOCKED
, WAITING
, ...), so calling them will corrupt the behavior of the JVM.
Noncompliant Code Example
Thread myThread = new Thread(new RunnableJob());
...
myThread.wait(2000);
© 2015 - 2025 Weber Informatics LLC | Privacy Policy