In Java, the Thread
class represents a thread of execution. Synchronization between threads is typically achieved using objects or
shared resources.
The methods wait(…)
, notify()
, and notifyAll()
are related to the underlying object’s monitor and are
designed to be called on objects that act as locks or monitors for synchronization. These methods are available on Java Object
and,
therefore, automatically inherited by all objects, including Thread.
Calling these methods on a Thread
may corrupt the behavior of the JVM, which relies on them to change the state of the thread
(BLOCKED,
WAITING,
…).
Noncompliant code example
Thread myThread = new Thread(new RunnableJob());
...
myThread.wait(); // Noncompliant