aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes About Object lock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About Object lock" Watch "About Object lock" New topic
Author

About Object lock

Niu Xiuyuan
Ranch Hand

Joined: Jun 08, 2001
Posts: 68
when wait() or sleep() function is invoked,if they hold the object lock?
code:
synchronized( lock )
{
wait();
}


Sun Certified Java Programmer<br />Sun Certified Web Component Developer
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
wait() does not hold the lock, sleep() does
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
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).]


SCJP2. Please Indent your code using UBB Code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About Object lock