Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread doubt

 
Marcelo Ortega
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?
 
raghu babu
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.
 
Santana Iyer
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic