Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help in Thread

 
Alan Hermin
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Alan Hermin
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Asha
but i think that question need more enhancement if the question need to select all that apply...
 
P Boon
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic