This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

notify(); doesn't work?  RSS feed

 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is a claculating thread




it is ok.But if i comment the notify(); method also it is working.How it possible?
 
Sheriff
Posts: 21464
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Threads / Synchronization.
 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at my question

here
 
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
You may have just won ten million dollars! Or, maybe a tiny ad.
Download Free Java APIs to Work with Office Files and PDF
htttp://www.e-iceblue.com/free-apis.html
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!