• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread states and Object lock

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

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.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic