All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.S2236.html Maven / Gradle / Ivy

On a Thread instance, methods wait(...), notify() and notifyAll() are available only because all classes in Java extends Object and therefore automatically inherit the methods. But there are two very good reasons to not call those 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 those method calls 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