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 wait() or notify()?? 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 "wait() or notify()??" Watch "wait() or notify()??" New topic

wait() or notify()??

Sun LiWei
Ranch Hand

Joined: Aug 10, 2002
Posts: 49
either a thread is blocked outside the synchronized code or in I/O,will it realse the lock and be added to the objet's wait pool??
if I never call wait(),need i call notify(),notifyAll().
really confused
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
Hi Sun:
I can not follow your question. Can you restate it? What do you mean by "blocked"?
[ September 12, 2002: Message edited by: Barkat Mardhani ]
Sun LiWei
Ranch Hand

Joined: Aug 10, 2002
Posts: 49

at line 1,if thread can't get the lock of monitor,it is blocked,and at line 3,it blocked.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
Sun when a thread arrives to a region of code protected by an unavaliable monitor, it blocks in the entry set of the monitor(aka mutex). It leaves it when the mutex becomes available and enters the region of the monitor to execute it and to access the shared variables. Being excutin the region of code protected by the monitor if it calls wait on that mutex it will stop execution and it will block being added to the waiting set of the mutex. It will stay there untill other thread will invoke notifyAll() or sometimes notify() on that mutex.
In this online chapter of Inside the Java 2 Virtual Machine by Bill Venners you can read much more.
There is also a picture about a monitor showing the entry and wait sets.
[ September 13, 2002: Message edited by: Jose Botella ]

SCJP2. Please Indent your code using UBB Code
I agree. Here's the link:
subject: wait() or notify()??
It's not a secret anymore!