Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
------------------------------------------------------------------------------------<BR>Velmurugan Periasamy<BR>Sun Certified Java Programmer for Java 2 Platform<BR>Sun Certified Web Component Developer for J2EE platform<BR>Sybase Certified EAServer Developer (similar to jCert level 3)<BR>------------------------------------------------------------------------------------<BR>Study notes for Sun Java Certification<BR><A HREF="http://www.geocities.com/velmurugan_p/" TARGET=_blank rel="nofollow">http://www.geocities.com/velmurugan_p/</A><BR>------------------------------------------------------------------------------------
------------------------------------------------------------------------------------<BR>Velmurugan Periasamy<BR>Sun Certified Java Programmer for Java 2 Platform<BR>Sun Certified Web Component Developer for J2EE platform<BR>Sybase Certified EAServer Developer (similar to jCert level 3)<BR>------------------------------------------------------------------------------------<BR>Study notes for Sun Java Certification<BR><A HREF="http://www.geocities.com/velmurugan_p/" TARGET=_blank rel="nofollow">http://www.geocities.com/velmurugan_p/</A><BR>------------------------------------------------------------------------------------
The notifyAll method should be called for an object only when the current thread has already locked the object's lock. Every thread in the wait set for the object is removed from the wait set and re-enabled for thread scheduling. (Of course, those threads will not be able to proceed until the current thread relinquishes the object's lock.)
Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
- Note the differences between blocked and waiting.
Blocked Waiting Thread is waiting to get a lock on the monitor. (or waiting for a blocking i/o method) Thread has been asked to wait. (by means of wait method) Caused by the thread tried to execute some synchronized code. (or a blocking i/o method) The thread already acquired the lock and executed some synchronized code before coming across a wait call. Can move to ready only when the lock is available. ( or the i/o operation is complete) Can move to ready only when it gets notified (by means of notify or notifyAll)
------------------------------------------------------------------------------------<BR>Velmurugan Periasamy<BR>Sun Certified Java Programmer for Java 2 Platform<BR>Sun Certified Web Component Developer for J2EE platform<BR>Sybase Certified EAServer Developer (similar to jCert level 3)<BR>------------------------------------------------------------------------------------<BR>Study notes for Sun Java Certification<BR><A HREF="http://www.geocities.com/velmurugan_p/" TARGET=_blank rel="nofollow">http://www.geocities.com/velmurugan_p/</A><BR>------------------------------------------------------------------------------------
One thread gets it, and the others go back to waiting.
Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Originally posted by Cherry Mathew:
I want to get one more doubt clarified.
I know that when a wait() is called the thread goes into the wait state but will a thread go into the wait or blocked state when it is tries to execute a synchronized block where lock is with another thread.
Wont it be better if all the threads waiting for the lock goes into the wait state and notify() method called at the end of each synchronized block.
Originally posted by V Srinivasan:
Yes Lilly,
I got it, you are right. It was my mind boggling issue for the past one week to "Explicitly" put on pen the flow of the Thread. V Srinivasan
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|