Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread states and Object lock

Saravanakumar Rajmohan
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a question taken K&B book.

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 thread A is notified or after two seconds.
b) After the lock on B is released or after two seconds.
c) Two seconds after thread A is notified.
d) Two Seconds after lock B is released.

The answer int he book is "A".

But i feel none of the answers are correct...

When a thread is placed on a waitset for an object and when someother thread issues a notification or when the waiting time elapses the thread comes out of the waiting state and starts competing for the lock and after acquiring the lock ,only then it becmoes runnable..

since after wait and when competing for the lock it gets into a blocking state which is "not runnable" ...

iam i right on this ?? can anyone confirm my this...

Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The details that you have mentioned are valid concerns, but I think that the wording of the question is flexible enough to include those details. The question only asks when the thread can become a "candidate"; it does not ask when the thread will actually run.

It is also important to remember that threads are implemented using native code; so we can not assume that the behavior is the same on every platform. For example, even the thread state diagrams that you see in textbooks are likely to be different in every textbook. That's because Java threads are actually implemented using platform specific code that existed long before the Java Language Specification was written. For that reason, the JLS can not even attempt to define the details of how threads work.

Since the JLS can not describe the details of threads the exam can not cover those details either.
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!