This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

About Object lock  RSS feed

 
Niu Xiuyuan
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when wait() or sleep() function is invoked,if they hold the object lock?
code:
synchronized( lock )
{
wait();
}
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wait() does not hold the lock, sleep() does
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Be careful Niu you will get an IllegalMonitorStateException if you run the code because wait has not been called over lock.
Make sure the following
synchronized(LOCK){
LOCK.wait();
}
This way you wont't get the mentioned exception
[This message has been edited by Jose Botella (edited January 01, 2002).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!