• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

thread

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .

thanx

kuldeep
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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().
^^^^

 
reply
    Bookmark Topic Watch Topic
  • New Topic