• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread Question

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the question and all the choices.
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic