The Object Class provides us with methods used interface with the Monitor-Based Synchronisation construct!
And as we know, all Classes in Java extend from the Object Class.
This ensures that just like Intrinsic Locks, the methods used for Monitor-Based Synchronisation is available to all Classes & objects!!

Diagram on thread states with regards to ObjectMonitors

Object Monitor Methods

Key Requirements

  • All five methods throw IllegalMonitorStateException if called without holding the object’s monitor lock
  • Must be called inside a synchronized block/method on the specific object
  • The calling thread must own the monitor of the object on which these methods are called

Object.wait()

  1. Releases the monitor lock and puts the thread in WAITING state
  2. Thread stays suspended until another thread calls notify() or notifyAll() on the same object
  3. Must reacquire the lock before returning
  4. Can throw InterruptedException

Object.wait(long timeout)

  1. Same as wait() but with a timeout in milliseconds
  2. Thread enters TIMED_WAITING state
  3. Automatically wakes up after timeout expires (even if not notified)
  4. Returns when notified, interrupted, or timeout occurs

Object.notify()

  1. Wakes up one arbitrary thread waiting on this object’s monitor
  2. The awakened thread must still reacquire the lock before proceeding
  3. If multiple threads are waiting, which one wakes up is not guaranteed
  4. Does nothing if no threads are waiting
  5. Does not release the lock

Object.notifyAll()

  1. Wakes up all threads waiting on this object’s monitor
  2. All awakened threads compete to reacquire the lock
  3. Generally safer than notify() to avoid missed signals
  4. Preferred when multiple threads might be waiting for different conditions
  5. Does not release the lock