Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Question

 
Fes D Gaur
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Mock test had the question:

Which of the following will definitely stop a thread from executing?

yield() was one of the answers. I know that yield() sends control back to the JVM and the JVM may pick up the same thread and start it again. So this questions is somewhat confusing. Could a question like this come on the Test?

Thanks,
Fes
 
Gokul Somasundaram
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the question and all the choices.
 
Akshay Kiran
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Fes D Gaur:
A Mock test had the question:

Which of the following will definitely stop a thread from executing?

yield() was one of the answers. I know that yield() sends control back to the JVM and the JVM may pick up the same thread and start it again. So this questions is somewhat confusing. Could a question like this come on the Test?

Thanks,
Fes


Not a good choice. what if there are no other threads waiting for the object lock? in that case, the same thread will obtain the lock (reentrant) and execute happily.
Thread.stop() is one, it is however deprecated. Thread.interrupt() would be a good choice, and maybe Thread.sleep() << but this one I'm not sure, because if it is sleep, it is still executing a command isn't it? not practically, but yes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic