aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes a thread stops Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "a thread stops" Watch "a thread stops" New topic
Author

a thread stops

mohamed hamdy
Ranch Hand

Joined: Feb 13, 2003
Posts: 72
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

Joined: Dec 20, 2001
Posts: 3271
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 ]

SCJP Tipline, etc.
mohamed hamdy
Ranch Hand

Joined: Feb 13, 2003
Posts: 72
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

Joined: Dec 20, 2001
Posts: 3271
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

Joined: Feb 25, 2003
Posts: 14
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.


They say..if you try sincerely you succeed...lets see!!
preeti khane
Ranch Hand

Joined: Mar 12, 2003
Posts: 93
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

Joined: Feb 25, 2003
Posts: 14
Thanks Preeti.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a thread stops