• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

wait and notify in Threads

 
K Vidhyakar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can Any body help in finding the answer for this question.

Which statement is true?
A. If only one thread is blocked in the wait method of an object, and another thread
executes the modify on that same object, then the first thread immediately
resumes execution.
B. If a thread is blocked in the wait method of an object, and another thread
executes the notify method on the same object, it is still possible that the first
thread might never resume execution.
C. If a thread is blocked in the wait method of an object, and another thread
executes the notify method on the same object, then the first thread definitely
resumes execution as a direct and sole consequence of the notify call.
D. If two threads are blocked in the wait method of one object, and another thread
executes the notify method on the same object, then the first thread that executed
the wait call first definitely resumes execution as a direct and sole consequence
of the notify call.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
option "B" is the correct answer.

Regarding option "C"


then the first thread definitely resumes execution as a direct and sole consequence of the notify call.


Very little is guaranteed in threads. Once a thread is blocked-for-lock-acquisition and when another thread calls notify this threads goesto ready-to-run state and NOT running state directly.

NOTE: This is NOT the correct forum for this(Thread) question.
 
Anurag Jain
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would agree and i have deleted my earlier post in favor of this correct answer!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic