Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a thread stops

 
mohamed hamdy
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm confused from the vocabulary regarding the questions about Threads is "stop" differs from "stop executing" ?
and does it means the thread becomes dead or blocked ( can run again ) ?
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It really depends upon the context of the question. In most cases, when someone talks about a thread "stopping," they're referring to an instance in which the thread has to wait (because it executed a line which caused it to block or wait for another thread, etc.) as opposed to a thread dying or completing execution.
But, like I said, it really depends on the context of the question.
If you have a particular practice question in mind, paste it here and we'll take a closer look at it.
[ April 04, 2003: Message edited by: Corey McGlone ]
 
mohamed hamdy
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Gorey
there's a question:
Under which circumstances will a thread stop?
1) The method waitforId() in class MediaTracker is called.
2) The run() method that the thread is executing ends.
3) The call to the start() method of the Thread object returns.
4) The suspend() method is called on the Thread object.
5) The wait() method is called on the Thread object.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, in this case, it looks like the word "stop" means any sort of stoppage, whether that means that the thread has finished its job or it has to wait for something. Let's look at the answers:
1) The method waitforId() in class MediaTracker is called.

Don't know about this one. There must have been some supporting code that came with this question because I have no idea what the MediaTracker class is.
2) The run() method that the thread is executing ends.
Yup. This would cause the thread to stop as it would be done executing at this point.
3) The call to the start() method of the Thread object returns.
No, this won't cause the thread to stop. The whole point of the start method is to kick off the thread. The run method is really the "lifeline" of the thread, not start.
4) The suspend() method is called on the Thread object.
Well, this is true, but suspend is deprecated and won't appear on the exam. Don't concern yourself with suspend and resume.
5) The wait() method is called on the Thread object.
Yup. This will also cause the thread to stop executing as it has to wait for a notify (or at least for a timeout).
I hope that helps,
Corey
 
Sarbani Mookherji
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Corey, it would be of great help if you would please explain this line once more.

--------------------------------------------------
2) The run() method that the thread is executing ends.
--------------------------------------------------

Thank you,
Sarbani.
 
preeti khane
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sarbani,
what that statement means is that
Case 1. if the thread was created by extending the Thread class then the run method of the extended Thread class will be executed
eg: Thread x = new MyThread(); where MyThread extends Thread
Case 2. If the thread was created by passing a runnable object to the Thread constructor, the the run method of the Runnable object instance will be executed or stopped
Thread x = new Thread(new MyRunnable());
where MyRunnable implements Runnable
Hope that helps
 
Sarbani Mookherji
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Preeti.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic