Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes need help in Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "need help in Thread" Watch "need help in Thread" New topic
Author

need help in Thread

Alan Hermin
Ranch Hand

Joined: Feb 16, 2006
Posts: 290
Hi All....
I am preparing for scjp 5....
in K&B book in chapter9 (Threads) . at the Q9 page 737 ...the K&B answer is (D: 12). but there are a possible situation in JVM called spontaneous wakeup
that may be notify the waited thread even though NO CODE has called notify(),,, and this situation occured not always....
I think that the answer to be correct is Both (B:123 and C:12)
Some expert tel me what is the exact answer and why?
Please Help
thanks

preparing scjp5
[ April 12, 2006: Message edited by: ali tareq ]
Asha Pathik
Ranch Hand

Joined: Feb 08, 2006
Posts: 143
Hi,

I don't know about "spontaneous wakeup" of a thread without the need of notify() method, but in exams i think we are suppose to select only those options which are guaranteed to occur always, not those which can or cannot happen depending on JVM.

Asha


SCJP 1.5
Alan Hermin
Ranch Hand

Joined: Feb 16, 2006
Posts: 290
Thanks Asha
but i think that question need more enhancement if the question need to select all that apply...
P Boon
Greenhorn

Joined: Oct 28, 2006
Posts: 1
I'm glad I found this thread(!), as exactly the same thing confuses me. The language spec (http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.8.1) states:

"[...] The thread may be removed from the wait set due to any one of the following actions, and will resume sometime afterward."

[...]

An internal action by the implementation. Implementations are permitted, although not encouraged, to perform "spurious wake-ups" -- to remove threads from wait sets and thus enable resumption without explicit instructions to do so. Notice that this provision necessitates the Java coding practice of using wait only within loops that terminate only when some logical condition that the thread is waiting for holds. [...]"

Also because the term "necessitates" is used here, I *think* "123" should be a correct answer as well. Shouldn't the starting-point be the language specification instead of the "major JVM implementation(s)" (whatever those are)?
[ October 28, 2006: Message edited by: P Boon ]
 
 
subject: need help in Thread
 
Similar Threads
Difference between notify and notifyAll
Need J2SE 5.0 MockExams Link
question about notify being called at random by the JVM
Question regarding notify() and wait()
Notify/Notifyall to be used with object or Thread?