• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please QuoteYourSources
 
Ranch Hand
Posts: 276
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: https://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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic