GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Notify() 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 "Notify()" Watch "Notify()" New topic
Author

Notify()

Alexsandra Carvalho
Ranch Hand

Joined: Jul 13, 2007
Posts: 75
Hello,

If I use threadB.wait() in threadA and in threadB I do not call notify(), when the run() method of threadB finishes, then the threadA continues like I had call notify() in threadB...

Why?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

Originally posted by Alexsandra Carvalho:
Hello,

If I use threadB.wait() in threadA and in threadB I do not call notify(), when the run() method of threadB finishes, then the threadA continues like I had call notify() in threadB...

Why?



This is an implementation detail -- which is of course, subject to change.

The join() method is implementated internally with the wait()/notifyAll(). A join() method call on the thread object does a wait() on the thread object. When the thread finishes, some of things that it does are, set the alive flag to indicate that it is not, and send a notifyAll() to all threads doing a join().

Obviously, you are not using the join() method, but you are waiting on the same notification object used by the join() method.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
HI
Can anybody explain me the above problem with solution using a suitable example.I am unable to understand this.


SCJP 5.0(75%), SCWCD 5.0(88%)
 
GeeCON Prague 2014
 
subject: Notify()