| 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: 12267
|
|
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
|
|
|