• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thread question

 
K Vidhyakar
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,
i dint understand the phrase "cannot directly cause a thread to stop executing" .
Which two CANNOT directly cause a thread to stop executing? (Choose Two)
A. Calling the yield method.
B. Calling the wait method on an object.
C. Calling the notify method on an object.
D. Calling the notifyAll method on an object.
E. Calling the start method on another Thread object.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what i can tell wait is the only option here that can stop a thread. So i dont understand why the question says ( Choose two ).
 
Abhijit Sontakey
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The answers would be notify and notifyAll().
wait() and yield directtly stop the current thread from executing.
However after invoking notify() and notifyAll() methods, the current thread doesn't stop executing, only after the current thread has completed, rest of threads can execute. If a thread calls start() method of another thread (threadB), if a VM runs another thread(threadB) current thread stops. Hence notify() and notifyAll() are right answers.
Let me know if this helps.

Regards
Abhijit.
 
Henry Wong
author
Marshal
Pie
Posts: 21190
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes... notify() and notifyAll() does not have a direct affect at stopping the current thread.

As for start(), it can have a direct affect, if the thread to be started is of a higher priority.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic