Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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().
 
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic