• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Stop a thread  RSS feed

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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."
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!