• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About Object lock

 
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