aspose file tools*
The moose likes Threads and Synchronization and the fly likes  notify(); doesn't work? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark " notify(); doesn Watch " notify(); doesn New topic
Author

notify(); doesn't work?

anarkali perera
Ranch Hand

Joined: Sep 10, 2009
Posts: 237
this is a claculating thread




it is ok.But if i comment the notify(); method also it is working.How it possible?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19541
    
  16

Moving to Threads / Synchronization.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
Look at my question

here


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 396

I think peoprl have already covered why the code doesn't work explaining its actual behaviour is quite complex but essentially you broke a very simple and well documented rule ...

wait's should always be in loops that test a flag on wakeup to determine if the notify was intentional

Read wait description here ...
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Object.html#wait%28long%29
and also most good books or bug finders will tell you the same thing ....

If you don't follow this rule, all bets are off with regards to something called 'spurious thread wake up' , now some people will tell you this doesn't exist or is an OS dependent thing ... however ...

in Java 1.5 (I think)?? Sun used the fact that the thread were laways allowed to spontanuosly wake up and signalled on thread death (to prevent programs such as yours lock up I think), this was reported as a bug against Java (see Sun site) but its not as its covered in the docs just previously didn't happen.

Quick Answer

Your code is badly formed and because of that your experience some none intuitive behaviour that's harder to explain.


"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: notify(); doesn't work?
 
Similar Threads
Lock Mechanism ?
K&B book example
wait and notify problem from K&B.
problem with wait()- notify()
Multithreading: How can total be nearly 5,000 even though loop is up to 100?