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...
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.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>