• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

directly stopping a thread

 
Nigel Patching
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could someone tell me which of these methods directly stop a thread:
wait()
start() called on a new thread
sleep()
notify()
yield()
 
Ryan Langley
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wait() (within a synchronized code block of course) will cause the thread to stop until it is interrupted.
start() (used with a Thread based object) will in effect branch a new thread off from the currently executing thread. Both threads will run (theoretically) in parallel.
sleep() will make the currently running thread stop executing for a specified period of time, and then continue.
notify() will interrupt a thread that has called wait().
yield() will cause a thread to suspend operation so that other threads of equal or higher priority will be allowed to run by the thread scheduler, which could be the same thread that called the yield() method. This is usually used if a thread is carrying out a complex computation so that other threads can have a chance to run.
Originally posted by Nigel Patching:
Could someone tell me which of these methods directly stop a thread:
wait()
start() called on a new thread
sleep()
notify()
yield()


------------------
Cheers,
RL
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic