• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

[Errata K&B?] SCJP Chapter 9 Q10

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Question 10 from Chapter 9 of K&B's book, the answer is A. I would have answered A and B. Can you explain why B is not correct ?

Question 10 page 750:

Assume the following method is properly synchronized and called from a thread A on an object B:

After calling this method, when will the thread A become a candidate to get another turn
at the CPU?
A. After object B is notified, or after two seconds.
B. After the lock on B is released, or after two seconds.
C. Two seconds after object B is notified.
D. Two seconds after lock B is released.

Also I think the is a mistake at page 731 where it's written:

The sentence should be: "it will NOT go"


Thanks in Advance for your help.
[ March 17, 2008: Message edited by: Jean-Luc Thirion ]
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,


maybe the answer B can be read like this: a lock is taken on B, we don't notify object B, we release the lock on B. Does this sequence make te thread A become a candidate to get another turn at the CPU.


imha
 
Jean-Luc Thirion
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the question is not clear enough.

Since the "notify" call should be in a synchronized block, like this:

Other thread than A, say T:

At point //2 , thread A is notified but has to acquire the lock on B. Unlike wait(), notify() does not release any lock. So Thread A gets a chance to run only at point //3 where the lock is released.

If I am right I think this question needs further clarifications in the K&B's book. Maybe I should then add the tag [Errata] or something like this to my post in order to draw attention to my post ?
 
Jean-Luc Thirion
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I added an errata to my initial post for p731 of K&B.

shoud be : It will NOT go ...
 
Let's go to the waterfront with this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic