Saturday, April 6, 2013

What happens when wait() & notify() method are called ?

When wait() method is invoked from a synchronized context, the following things happen

  1. The calling thread gives up the lock.
  2. The calling thread gives up the CPU.
  3. The calling thread goes to the monitor's waiting pool.

And in case of notify() method, following things happen

  1. One of the waiting thread (may be a random thread) moves out of the monitor's waiting pool.
  2. Thread comes into ready state (RUNNABLE).
  3. Tries its best to require the monitor lock before it can proceed to the method execution.

No comments:

Post a Comment

Your comment will be published after review from moderator