• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wait method

 
Basanti Mathad
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the thread does release the lock. Please see the javadoc for the Object.wait method.
 
Sarma Lolla
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although the memory aid contest is over I can't resist the temptation to suggest the following: "Join me as I yield to sleep."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic