aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes wait() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "wait() method " Watch "wait() method " New topic
Author

wait() method

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12788
    
    5
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
Rong Chen
Ranch Hand

Joined: Aug 07, 2000
Posts: 30
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: wait() method