File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes if wait() can't immediately reacquire the lock, then...? 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 "if wait() can Watch "if wait() can New topic
Author

if wait() can't immediately reacquire the lock, then...?

John M. Gabriele
Ranch Hand

Joined: Feb 18, 2001
Posts: 232

how do we ever make it to checkpoint d? right after checkpoint b
we tell the other thread waiting on the Object (by calling
obj.notify() ) that it's wait() should try to reacquire the lock
on the Object so it may continue. *But* since we drag our feet
with the sleep(), during that time, shouldn't the other thread's
wait() see that it cannot get the lock at this time, and just go
back to wait()'ing?
John M. Gabriele
Ranch Hand

Joined: Feb 18, 2001
Posts: 232
whoops! i understand it now.
calling notify() on an object upon which other threads are
wait()'ing simply switches the waiting thread's "state" from,
waiting regardless of whether or not the object has a lock on it
to
waiting to grab the object's lock as soon as it is available.
i hope this post helped others. it helped me. heh.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: if wait() can't immediately reacquire the lock, then...?