SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
when i use notify i get the following output:
D:\scjp>javac Reader.java
D:\scjp>java Reader
A waiting for calculation....
C waiting for calculation....
B waiting for calculation....
going inside Calculators syn block
inside Sync block
Total of Thread Ais4950
Total of Thread Bis4950
Total of Thread Cis4950
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
All code in my posts, unless a source is explicitly mentioned, is my own.
K&B wrote:it's possiblethat a thread has accidentally sent an extra notify() that was not intended.
There's also a possible situation called spontaneous wakeup that may exist in some
situations—a thread may wake up even though no code has called notify()
or notifyAll(). (At least, no code you know about has called these methods.
Sometimes the JVM may call notify() for reasons of its own, or code in some other
class calls it for reasons you just don't know.)
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
All code in my posts, unless a source is explicitly mentioned, is my own.
SCJP 6
Why to worry about things in which we dont have control, Why to worry about things in which we have control ! !
SCJP 6
All code in my posts, unless a source is explicitly mentioned, is my own.
Hope you have K&B 6 book .In page 755 , the book tells the reason for this behaviour as told by Ruben...
Here is part of that paragraph..
K&B wrote:
it's possiblethat a thread has accidentally sent an extra notify() that was not intended.
There's also a possible situation called spontaneous wakeup that may exist in some
situations—a thread may wake up even though no code has called notify()
or notifyAll(). (At least, no code you know about has called these methods.
Sometimes the JVM may call notify() for reasons of its own, or code in some other
class calls it for reasons you just don't know.)
The moral here is that when you use wait() and notify() or notifyAll(), you should almost always also have a while loop around the wait() that checks a condition and forces continued waiting until the condition is met
SCJP 6
All code in my posts, unless a source is explicitly mentioned, is my own.
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |