It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes wait(), notify(), notifyAll() doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "wait(), notify(), notifyAll() doubt" Watch "wait(), notify(), notifyAll() doubt" New topic
Author

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

Gari Jain
Ranch Hand

Joined: Jun 29, 2009
Posts: 100


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?


OCPJP 6-100%; Preparing for GATE11
Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 432

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.


SCJP 6 | FB : Java Certifications-Help. | India Against Corruption
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Please QuoteYourSources


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

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.


OCPJP 6
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
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

Joined: Jun 23, 2010
Posts: 432

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

Joined: Aug 03, 2010
Posts: 37
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.


Cheers,
Divyesh.
Anton Brass
Greenhorn

Joined: Sep 08, 2010
Posts: 25
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: wait(), notify(), notifyAll() doubt
 
Similar Threads
notify and notifyAll
Help correct this calculator thread
wait and notify
Threading discrepancies
dubt in notifyAll