• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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.
[email protected]
 
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().
^^^^

 
I'm full of tinier men! And a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic