File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread states and Object lock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread states and Object lock" Watch "Thread states and Object lock" New topic
Author

Thread states and Object lock

Saravanakumar Rajmohan
Greenhorn

Joined: Jul 08, 2003
Posts: 17
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:

wait(2000);

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...

Thanks.
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
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>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Thread states and Object lock
 
Similar Threads
Thread Question
Test Question about Threads
Doubt on wait method in Threads
[Errata K&B?] SCJP Chapter 9 Q10
Wait with timeout