• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Thread doubt  RSS feed

 
Ranch Hand
Posts: 528
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question:

Thread Z holds the lock on object A. Thread X is blocked inside a wait call on ObjectA.

What allows thread X to become runnable?
A. Thread X is interrupted.
B. Thread X is interrupted.
C. Thread X�s wait() times out.
D. Thread Z calls Thread.sleep(100);
E. Thread Z releases the lock on A and calls the notify() method on thread X
F. Thread Z releases the lock on A and calls the notifyAll() method on objectA.
Answer given: F

I thought it would of been C and F???

Can anyone clarify this?
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marzo,

A and B has same text, but I'm thinking A,C and F instead just F.

I hope someone would clarify our understanding.
 
Marcelo Ortega
Ranch Hand
Posts: 528
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh sorry thats a typo.
 
Ranch Hand
Posts: 335
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marzo,

Thread Z holds the lock on object A. Thread X is blocked inside a wait call on ObjectA.

C. Thread X�s wait() times out.

No, as even if X's wait times out X remains in non runnable state because it must acquire lock on object A which is hold by thread Z, after acquiring lock on object A, thread X can go to runnable state.

Other example is say when we call notify on object A in thread Z, now thread waiting for object lock (Thread X) does not go directly to Runnable it must wait and acquire lock on object A than only it can go to runnable.

(calling notify does not immediately release lock, only after synchronized method or block completes than only lock is released on object A by thread Z, now X thread can acquires lock and can make transition to runnable state).

Hope this helps,
bye.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!