mohitkumar gupta wrote:
is it necessary to have wait,notify in synchronized block or method
Yes, it's necessary.
Wait and Notify provides a means of communication between threads which are synchronized on the same object.
When a
Thread calls wait() method in synchronized context, it releases the object lock and waits.
Invoking notify() method from other thread occupying that object lock wakes up the waiting thread.