File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "need help in Thread" Watch "need help in Thread" New topic

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

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

Joined: Feb 08, 2006
Posts: 143

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.


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

Joined: Oct 28, 2006
Posts: 1
I'm glad I found this thread(!), as exactly the same thing confuses me. The language spec ( 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 ]
I agree. Here's the link:
subject: need help in Thread
It's not a secret anymore!