aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "K&B" Watch "K&B" New topic
Author

K&B

Shweta R Dhaneshwar
Ranch Hand

Joined: May 27, 2005
Posts: 35
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?


Shweta Dhaneshwar.<br />SCJP 1.4 90%
Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

I'm inclined to agree with you in that it's a poorly-worded question. The call to wait() *can* throw a runtime IllegalMonitorStateException.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: K&B
 
Similar Threads
Threads and Synchronization examples
Threads Notes for Exams
join() mock exam question
a question about thread method
JTest and threads