• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wait() or notify()??

 
Sun LiWei
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sun:
I can not follow your question. Can you restate it? What do you mean by "blocked"?
Thanks
Barkat
[ September 12, 2002: Message edited by: Barkat Mardhani ]
 
Sun LiWei
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic