Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Gari Jain
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?
 
Arjun Srivastava
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.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
 
Vinoth Kumar Kannan
Ranch Hand
Posts: 276
Chrome Java Netbeans IDE
  • 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.
 
Ireneusz Kordal
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.
 
Divyeshh Patel
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.
 
Anton Brass
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic