• Post Reply Bookmark Topic Watch Topic
  • New Topic

After wait shoudln't thread be in blocking state rather than runnable state?  RSS feed

 
Harish Kommaraju
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am going through SCJP 6 book by Kathy Sierra & Bert Bates. A sample code snippet is given below from Threads chapter, where I need a clarification


Now my doubt is, after 2 seconds of wait time, to continue further code execution, the above code would require the lock on object 'a' and there is fair chance that the other thread (which is supposed to call notify() on a) might already be holding a lock on it.

So shouldn't the thread go to Blocking state after 2seconds wait, instead of Runnable state as mentioned above in the comments (in Line No. 2).

Kindly clarify what am I missing here.

Thanks & Regards,
Harish
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are entirely correct. The thread must go to Blocking, and reacquire the lock, before it enters Runnable.
 
Harish Kommaraju
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mike for the confirmation. I will try to inform the authors to make this correction, as it could confuse newbies.

Can any one please let me know how can I intimate SCJP 6 authors (Kathy / Bert) regarding this correction? Is there any separate group for that in this forum?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!