• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Q from jexam

 
anil bisht
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following will definitely stop a thread from executing:
wait()
notify()
yield()
suspend()
sleep()
the answer given is a,c,d,e
but how come c. if there is no other thread then it wont stop the thread .. and the resoning given was

Only notify() will not explicitly stop an executing thread from running. Yield() returns control back to the JVM, which may or may not stop the thread from running.

( so its no definite )
if the Q was whcih of the following can stop the thread then yield() is one of the answer ..
correct me if i am wrong ..
anil
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tend to agree with you anil, but I think what they are saying, is that yield() will stop the thread and move it into the ready state, and then if no other threads can start then it will be put back into the running state. So basically it does stop it for a while. But I don't like the question much.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic