• 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

wait() method

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 halt until another object sends a notify() or notifyAll() method
C. An exception will be raised
D. The object issuing the call to wait() will be automatically synchronized with any other objects using the receiving object
The answer given is b, but IMO answer should be b,c. bcoz wait() method gives InterruptedException.
Please give ur opinion..
--Shallender
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That question is badly stated. Only Threads execute calls to methods. A Thread "A" with a synchronized lock on an object can call wait() and enter a waiting condition.
Another Thread "B" with a synchronized lock on the SAME object can call notify() or notifyAll() and the waiting Thread will enter the runnable condition. When Thread B loses the synchronized lock on the object, Thread A gets a chance to run.
You get a RuntimeException (I forget the exact type) if your Thread calls wait or notify or notifyAll WITHOUT having a synchronized lock on the object.
Don't think of wait etc as affecting an object but as affecting a Thread executing a method.
Bill
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
wait(), notify() and notifyall() methods must be executed in synchronized code, otherwise the call will result in an IllegalMonitorStateException.
So an Exception isn't always raised after wait().
 
reply
    Bookmark Topic Watch Topic
  • New Topic