but expecting output to be 1000 and program execution should never finish , because two Reader threads should not be woken up by notify() . Can someone please explain how notify() notified all the three Reader threads ?
I'm not sure what point you are trying to make with your last code snippet. It is obvious that it will never complete as the main thread is set to wait until another thread has a chance to run. There is no other thread so its wait is indefinite.
Ravi Tej Pidatala wrote:If two Reader threads are waiting for notify() call from Calculator thread, they would be in waiting state. So either program execution should not finish , or interruptedException should be thrown ?
Ravi Tej Pidatala wrote:When I comment out the code of line 19 , I am seeing that i am getting same output. It means probably JVM is calling notify() on these threads.
What you are seeing is an implementation detail of the threading system -- the threading system uses the threading object to implement join(). The join() method will call wait() on the thread object while the thread is alive -- and part of the shutdown for a thread is to do a notify all on the thread object.
Basically, try not to use the thread object for wait() -- as it is already in use internally.