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.