The following code is given in K&B book in chapter Threads.
When i tried Running it....It is giving Exception, i am not understanding why it is giving ???
Runtime error :-
java ThreadTesting
Exception in
thread "Thread-3" java.lang.IllegalMonitorStateException
at java.lang.Object.notify(Native Method)
at ThreadB.run(ThreadTesting.java:23)
4950
Moreover i am also not understanding why it is being assumed that after b.start() main thread continues and synchronized(b) would be executed.
It may also happen that threadB executes first, gets the lock and calculates total and then synchronized(b) would get executed. If it may happen then what is the use of b.wait() ....infact threadB is already done and now no notification would also come from it. A full chaos....
Please anyone explain this wait() notify() confusion.
All hell broke Lose !!!