This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

wait(), notify(), notifyAll() doubt

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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?
 
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gari Jain wrote:
wait(), notify(), notifyAll(),serialization


These topics are no longer in syllabus of SCJP6, you can skip these topics if you are preparing for exam.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
 
Ranch Hand
Posts: 276
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gari, if you still want to know the reason for that kind of behavior, you can take a look at this thread. See if it helps.
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Arjun Srivastava wrote:

Gari Jain wrote:
wait(), notify(), notifyAll(),serialization


These topics are no longer in syllabus of SCJP6, you can skip these topics if you are preparing for exam.



See this thread: http://www.coderanch.com/t/509640/java-programmer-SCJP/certification/Cleared-OCPJP-morning
Someone got 4 questions on synchronization/wait/notify on the exam this morning.
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!