This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
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 Head First Android this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "wait method" Watch "wait method" New topic

wait method

Basanti Mathad
Ranch Hand

Joined: Aug 27, 2002
Posts: 60
I know that the wait/notify shld be called in the synchronized block.But does the thread give up the lock while waiting?
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="" 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

Joined: Mar 22, 2000
Posts: 12982
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.
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."
It is sorta covered in the JavaRanch Style Guide.
subject: wait method
It's not a secret anymore!