File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes thread Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "thread Question" Watch "thread Question" New topic
Author

thread Question

mohamed hamdy
Ranch Hand

Joined: Feb 13, 2003
Posts: 72
look to this question.
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
the answer is C,D ( which i correctly guessed)
but why E isn't right, is calling start of another thread will give the action of calling yield to give the new thread to compete fairly with the caller thread for the scheduler to run it?
Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298
from Thread class api:
"Causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread.
The result is that two threads are running concurrently: the current thread (which returns from the call to the start method) and the other thread (which executes its run method). "
I agree with you, start cannot cause a thread to stop executing since ""The result is that two threads are running concurrently"".
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
"Which two CANNOT directly cause a thread to stop executing?"
The start method is used to start another thread that appears to be executing simultaneously with other threads. If the computer has only one CPU then only one thread is able to run at any point in time and the thread scheduler will decide which runs and which does not. The thread that invokes the start method will stop if the thread scheduler decides to let the new thread run. Otherwise, the original thread continues to run while the new thread remains in the ready state.
The notify and notifyAll methods can not directly cause a thread to stop running because the notify and notifyAll method have no impact until the invoking thread gives up the monitor that is required by the waiting thread.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
We don�t know much about what the start method does. This is what we know,
j2se/src/share/classes/java/lang/Thread.java
public synchronized native void start();
j2se/src/share/native/java/lang/Thread.c
static JNINativeMethod methods[] = {
{"start", "()V", (void *)&JVM_StartThread},
We also know that invoking the start method of a Thread object in some unknown way and at some unknown time causes the Java Virtual Machine to execute the run method of the object.
And we know that invoking the start method more than once results in an IllegalThreadStateException.
Otherwise what we say is derived from our general knowledge of how operating systems behave.
E is right or wrong depending on the implementation of the JVM.
[ March 29, 2003: Message edited by: Marlene Miller ]
 
 
subject: thread Question
 
Similar Threads
stoping execution.
thread question
Stop the Thread
Questions on Thread and Exception
The conflicting answers for these 2 questions!