Ireneusz Kordal wrote:
See this thread
Someone got 4 questions on synchronization/wait/notify on the exam this morning.
have already saw, but they are just statements(true or false), not the codes related to wait and notify.
still it helps others to focus on these topics too.
Gari Jain wrote:
The notify() method is used to send a signal to one and only one of the
threads that are waiting in that same object's waiting pool.
then when i run this code..how come all the readers are notified?
Gari,
If you haven't already figured it out, even the notify() call in this program is superfluous.
You can run the program after removing that call and you will get the same result.
To spare you the reading of the threads, it seems that after run() finishes notifyAll() is triggered. Your Calculator class is extending Thread and using the run() method. After finishing its calculations the run() method ends and notifyAll() is triggered automatically.
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
Gift giving made easy with the permaculture playing cards