aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Stop a thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Stop a thread" Watch "Stop a thread" New topic
Author

Stop a thread

Bojan Knezovic
Ranch Hand

Joined: Nov 20, 2003
Posts: 90
These are really two sets of answers but the question is the same:
Which two CANNOT directly cause a thread to stop executing? (Choose Two)
A.Exiting from a synchronized block
B.Calling the wait method on an object
C.Calling notify method on an object
D.Calling read method on an InputStream object
E.Calling the SetPriority method on a Thread object
(Answers: a, c)
Which two CANNOT directly cause a thread to stop executing? (Choose Two)
A.Calling the yield method
B.Calling the wait method on an object
C.Calling the notify method on an object
D.Calling the NotifyAll method on an object
E.Calling the start method on another Thread object
(Answers: c, d)
In the first case the B (wait method) can or cannot block (stop) the thread - it depends on the owner of the object's lock. Do D and E have anything to do with thread behaviour or they're put there only to fill up the space?
BTW .setPriority() can be used to change the priority of the thread that's already executing?
In the second case I think the only answer that MIGHT stop a thread is B (wait method, but then again it depends on the owner of the lock) - yield() doesn't guarantee anything since it's platform dependent (but it sure MIGHT and should yield to another thread) and start() method should move another thread to ready/runnable but it won't stop the currently executing thread (so it should be included in the list of the correct answers)!
These questions are supposedly similiar to the ones that will be asked in the exam - I hope they're gonna be a bit more specific!? :roll:
B.
Adrian Pang
Ranch Hand

Joined: Feb 20, 2004
Posts: 40
Here's what I think:
I think when the question ask for "cannot", that means it "will not under all circumstances". So, in cases where it's "maybe", it does not classify as "cannot."
For question 1, D can potentially blocks (e.g., no data to read), so it will make the thread stop executing. E differs by platforms; on some platforms perhaps a thread that is set to a lower priority stops running. (not sure -- correct me if I am wrong)
The question 2, yield and wait is a "maybe" so it is not a "cannot." For start, depending on the platform, if the new thread has a higher priority, the original thread might get preempted and stop executing. It's again a "maybe" instead of a "cannot."


SCJP 1.4, SCWCD 1.4, SCBCD 1.3
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stop a thread
 
Similar Threads
About Thread question?
thread problem
a simple question
My Confusion About Thead
The conflicting answers for these 2 questions!