GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads 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 "Threads" Watch "Threads" New topic
Author

Threads

Anushkha Rana
Greenhorn

Joined: Apr 13, 2003
Posts: 17
Question:
What is the method used to schedule a thread for execution?
Answer given is run()
I think correct answer should be start().
Question:
What is true about threads that stop executing?
A.When a running thread's suspend() method is called, then it is indefinitely possible for the thread to start.
B.The interpreter stops when the main method stops.
C.A thread can stop executing when another thread is in a runnable state.
Can somebody help me get the meaning of option A.
And correct answer to this question.
Rory French
Ranch Hand

Joined: Apr 03, 2003
Posts: 97
I agree with you Anushkha. I think the answer should be start(). Simply calling run()does not bring about the creation or scheduling of a new thread.
As for the second question:

Question:
What is true about threads that stop executing?
A.When a running thread's suspend() method is called, then it is indefinitely possible for the thread to start.
B.The interpreter stops when the main method stops.
C.A thread can stop executing when another thread is in a runnable state.

option A does seem completely devoid of meaning, but it could also be very badly worded. If you read the Java documentation for the suspend() method, you'll see that a thread can be suspended permanently (or indefinitely) because it does not resume, or due to deadlock.

public final void suspend()
Deprecated. This method has been deprecated, as it is inherently deadlock-prone. If the target thread holds a lock on the monitor protecting a critical system resource when it is suspended, no thread can access this resource until the target thread is resumed. If the thread that would resume the target thread attempts to lock this monitor prior to calling resume, deadlock results. Such deadlocks typically manifest themselves as "frozen" processes.

But saying that it is indefinitely possible for the thread to start, is a bit of a contradiction, because if a thread is deadlocked or indefinitely suspended, then it will surely never start or resume.
So I think option A is false .
[ April 16, 2003: Message edited by: Rory French ]
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
I also agree. You could define a class that implements the Runnable interface and then invoke the run method without every creating a Thread object. Or you could create a Thread object and pass it the Runnable object and then invoke run without ever invoking Thread.start.
The Java Programming Language separates the notions of thread and run this way: Threads abstract the concept of a worker-an entity that gets something done. The work done by a thread is packaged in its run method.
Kathy Sierra
Cowgirl and Author
Ranch Hand

Joined: Oct 10, 2002
Posts: 1572
Howdy -- these are *not* well-worded questions, from the exam point of view, for the following reason:
* suspend() is deprecated, NOT meant to be used any longer, and is definitely not on the exam!
* we would never use the word "schedule" in a question unless we were referring specifically to the thread scheduler, which you cannot control but can only 'influence'. So the idea of using the word 'schedule' here makes me cringe in horror
You might be able to say something like, "Which method makes a thread *eligible* for thread scheduling or *eligible* for becoming the currently-executing thread..."
And that would be start(), not run(). Because ANYBODY can call the run() method, and calling the run() method alone is not enough to cause a Thread object to become a 'thread of execution' (where it gets its own stack and has true threadness).
In other words, the run() method has to be called NOT by the programmer, but by the thread itself as a result of the programmer invoking start() on the thread...
And no matter what, there is NEVER any Fur involved
cheers,
kathy


Co-Author of <a href="http://www.amazon.com/exec/obidos/ASIN/0596007124/ref=jranch-20" target="_blank" rel="nofollow">"Head First Design Patterns"</a><br /> <br />Just a Jini girl living in a J2EE world.
Anushkha Rana
Greenhorn

Joined: Apr 13, 2003
Posts: 17
Hi all,
Though late, still thanx for replying and helping me out. Somehow, i don't get the mails for my postings.
Thanx again
 
GeeCON Prague 2014
 
subject: Threads