hello Q. what is the effect of issuing a wait() method on an object . A. if a notify() method has already been sent to that object then it has no effect. B. the object issuing the call to wait() will hait untill another object sends a notify or notifyAll(). C. an exception will be raised. D. the object issuing the call wait() will be autometically synchronized with any other objects using the receiving object.
the answer is B but i could not get the question & also the answer .
Hi Kuldeep, This is a simple case of a wait() and notifiy() methods to handle Threads. In addition we have the notifyAll() method. All these 3 methods are relevant to synchronized methods. They can be called only from within a method which has been declared - synchronized. When a wait() method is used, it is telling the thread to vacate the synchronized lock(in other words - monitor) and go to sleep till any other thread enters the monitor and calls the notify() method. When a notify() method is issued, as mentioned above, calls the first thread which had called wait() on a particular object. Similarly, a notifyAll() wakes up all the threads sleeping due to calling the wait() method. Hope it helps Niraj
What happens when wait() is called is this : currently executing thread gives up LOCK - monitor and goes into the pool of threads waitng for that object. This allows any other waiting thread in the objects monitor to acquire the lock and start executing the code in the synchronised block. Shrinivas ------------------ Sun Certified programmer for Java2 platform. Shri_mk@hotmail.com
I think none of them are true. for B: B. the object issuing the call to wait() will halt until another object sends a notify or notifyAll(). Is that the correct answer should be : B. the object issuing the call to wait() will halt the thread until same object sends a notify or notifyAll(). ^^^^
What's that smell? I think this tiny ad may have stepped in something.
a bit of art, as a gift, that will fit in a stocking