aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Execution Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads Execution" Watch "Threads Execution" New topic
Author

Threads Execution

Arathi Rajashekar
Ranch Hand

Joined: Nov 20, 2001
Posts: 112
Which methods may cause a thread to stop executing?
sleep();
stop();
yield();
wait();
notify();
notifyAll()
synchronized()
I feel the answer is 1,2,4
But given answer is 1,2,3,4
I think yield will stop the thread only if the other high priority thread or equal priority thread is waiting. If no threads are in waiting the yield method executes the current thread.
But look the other question
which of these will always cause a running thread to temporarily stop?
A)Calling a sleep()
B)calling yielsd()
C)The run() calling system.exit(0)
D)starting another thread with a higher priority thread
E)None of the above
Answere is a
I do agree with this
Any other answrs
Thanks in advance


Arathi<br />Sun Certified Java Programmer
ersin eser
Ranch Hand

Joined: Feb 22, 2001
Posts: 1072
may cause vs. will always cause
Stephen Tallamy
Greenhorn

Joined: Jan 08, 2002
Posts: 16
The difference is that the first question says may cause a thread to stop executing. As you rightly say, calling yield may stop the thread if another thread is scheduled to start (this depends on the scheduler).
In the second question it says, will always cause a running thread to temporarily stop. sleep() is the only thing listed that does this.
It's all in the wording of the question
doug thompson
Greenhorn

Joined: Jan 08, 2002
Posts: 4
what happens when sleep( 0 ) is called?
Deepti Dixit
Greenhorn

Joined: Dec 27, 2001
Posts: 17
In the question :
Which of these will always cause a running thread to temporarily stop?
A)Calling a sleep()
B)calling yielsd()
C)The run() calling system.exit(0)
D)starting another thread with a higher priority thread
E)None of the above
Why is that only A is the correct answer. D would also cause the current thread to stop temporarily. Is it not so ?
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
A synchronized method or a synchronized block *may* stop a thread from executing if another thread already has the monitor for the object in question.
Is the reason that item #7 of the first question (synchronized()) not a valid answer because the question asked specifically about which "methods" may cause a thread to stop, and synchronized() is not really a method?
Seems like a subtle play of words.


Rob
SCJP 1.4
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Ok, I answered my own question 3 minutes later.
"synchronized" is a modifier, not a method.
silly me
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Threads Execution