wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes wait method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "wait method" Watch "wait method" New topic
Author

wait method

Basanti Mathad
Ranch Hand

Joined: Aug 27, 2002
Posts: 60
hi,
I know that the wait/notify shld be called in the synchronized block.But does the thread give up the lock while waiting?
thnks
basanti
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Yes, the thread does release the lock. Please see the javadoc for the Object.wait method.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Sarma Lolla
Ranch Hand

Joined: Oct 21, 2002
Posts: 203
Sleep is the only method doesn't release locks on the objects. Please correct me if I am wrong.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
sleep and yield do not affect locks so sleeping or yielding in a synchronized block may get you in trouble. The JavaDocs for Thread are clear on this.
Bill
Dan Culache
Ranch Hand

Joined: Jan 24, 2003
Posts: 70
join doesn't release locks either. SO I believe the whole list is sleep, yield, join, suspend although suspend is obsolete and there are no questions about obsolete methods on the exam.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Although the memory aid contest is over I can't resist the temptation to suggest the following: "Join me as I yield to sleep."
 
 
subject: wait method
 
Similar Threads
Is JBoss free?
Happy National Pie Day
SCDJWS Beta Results
very very urgent...pl respond..
[Cricket] Will Australia lose to Bangladesh?