File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About Object lock" Watch "About Object lock" New topic

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?
synchronized( lock )

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
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:
subject: About Object lock
It's not a secret anymore!