• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a sample question from sun on threads

 
David De La Roche
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I was wondering could anybody give me a few pointers on what this question from the Sun sample questions page(http://suned.sun.com/USA/certification/devsq.html) is all about.
it's not that i don't know a decent bit about threads. i have completed my project and it is thread safe but i just don't really understand what the question is really asking.
the rest of the questions seem very straight forward. maybe i am looking for something more complicated that necessary.
You are about to create a new class that will have part of its behavior serve as the starting point for a separate thread. Which of the following is/are true?
The class must extend Thread
The class must implement Runnable
Behavior that is to run in a separate thread must be entirely contained in a method public void run()
Behavior that is to run in a separate thread must be entirely enclosed in a synchronized block
The new class must provide its own thread
The only correct answer is 2) The class must implement Runnable.
It is not necessary for the class itself to inherit from Thread (but note that is this is the case, the class will unavoidably implement Runnable, because Thread implements Runnable). While the starting point of a new thread's execution is the public void run() method, the scope of execution by another thread is not limited to that method. Synchronized blocks are not required for thread execution, rather they are used to control the interactions of concurrent threads. Finally, there is no requirement for the class to provide its own thread, indeed it is commonplace to deliberately create Thread objects and provide them with other Runnable objects to execute.
the smallest help appreciated.
dr
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think all they're getting at is prompting you to state what the absolute requirements are, given the question. In other words, which of these statements has to be true, as opposed to merely could be true.
So yeah, you're probably trying to read something into it, but with Sun sample questions, there's always that sneaking feeling that you can't tell if the question is hoping for more or less insight by way of an answer.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic