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.
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 ]
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.
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