• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

K&B

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question is from K&B

Solution:

D and F. D is correct because the wait() method is overloaded to accept a wait duration
in milliseconds. If the thread has not been notified by the time the wait duration has elapsed,
then the thread will move back to runnable even without having been notified. F is
correct because wait()/notify()/notifyAll() must all be called from within
a synchronized, context. A thread must own the lock on the object its invoking
wait()/notify()/notifyAll() on.
A is incorrect because wait()/notify() will not prevent deadlock. B is incorrect
because a sleeping thread will return to runnable when it wakes up, but it might not necessarily
resume execution right away. To resume executing, the newly awakened thread must still be
moved from runnable to running by the scheduler. C is incorrect because synchronization prevents
two or more threads from accessing the same object. E is incorrect because notify() is not
overloaded to accept a duration. G and H are incorrect because wait() and sleep() both
declare a checked exception (InterruptedException).



What I wan't to know is that...why g is not correct choice.Isn't it true that we get a runtime exception if wait and notify are not called from the synchronized block?
 
Ranch Hand
Posts: 657
Spring VI Editor Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm inclined to agree with you in that it's a poorly-worded question. The call to wait() *can* throw a runtime IllegalMonitorStateException.
 
reply
    Bookmark Topic Watch Topic
  • New Topic