The thread.yield method is intended to cause the currently executing thread to move from the running state to the ready state and offer the thread scheduler an opportunity to allow a different thread to execute based on the discretion of the thread scheduler. The thread scheduler may select the same thread to run immediately or it may allow a different thread to run. The thread.yield method is a native method so the behavior is not guaranteed to be the same on every platform.
Whatever doesn't kill us ...<br />Is probably circling back for another try.<br />SCJP 1.4
Whatever doesn't kill us ...<br />Is probably circling back for another try.<br />SCJP 1.4
The second call to a1.start will always cause an IllegalThreadStateException to be thrown. It is also possible that thread a1 might start running immediately causing the letter A to be printed before the second attempt is made to start thread a1. Although thread a1 might sometimes run to completion before the exception is thrown this result will not always occur.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Originally posted by Shishio San:
Hi Dan,
I think that the following comment about question 14 needs to emphasize the fact that the yield method gives only threads of the same priority a chance to run. If there are no equal priority threads that are runnable, then the yield is ignored.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
How do you feel about this new version?
Could you please post a link to the source of information that mentions the limitation concerning lower priority threads?
Whatever doesn't kill us ...<br />Is probably circling back for another try.<br />SCJP 1.4
Question 14
Which of the following is true?
a. The Thread.yield method might cause the thread to move to the blocking state.
b. The Thread.yield method might cause the thread to move to the ready state.
c. The same thread might continue to run after calling the Thread.yield method.
d. The Thread.yield method is a static method.
e. The behavior of the Thread.yield method is consistent from one platform to the next.
f. The Thread.sleep method causes the thread to move to the blocking state.
g. The Thread.sleep method causes the thread to move to the ready state.
h. None of the above.
The thread.yield method is intended to cause the currently executing thread to move from the running state to the ready state and offer the thread scheduler an opportunity to allow a different thread to execute based on the discretion of the thread scheduler. The thread scheduler may select the same thread to run immediately or it may allow a different thread to run. The thread.yield method is a native method so the behavior is not guaranteed to be the same on every platform. However, at least some implementations of the yield method will not yield to a thread that has a lower priority.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Question 18
Which of the following are true?
a. The Thread.run method is used to start a new thread running.
b. The Thread.start method is used to start a new thread running.
c. The Runnable interface declares the start method.
d. The Runnable interface declares the run method.
e. The Thread class implements the Runnable interface.
f. If an Object.notify method call appears in a synchronized block, then it must be the last method call in the block.
g. No restriction is placed on the number of threads that can enter a synchronized method.
h. Some implementations of the Thread.yield method will not yield to a thread of lower priority.
i. None of the above.
The Object.notify method can only be called from within a synchronized block by the thread that holds the monitor for that object. Suppose that thread T1 is holding the monitor for an object, A, within a synchronized block. If thread T1 calls the notify method immediately after entering the synchronized block, then no other thread can grab the monitor for object A until T1 leaves the synchronized block. For that reason, the transfer of control from thread T1 to any waiting thread can not be accelerated by moving the notify method to an earlier point in the synchronized block. The behavior of Thread.yield is platform specific. However, at least some implementations of the yield method will not yield to a thread that has a lower priority. Invoking the Thread.yield method is like offering a suggestion to the JVM to allow another thread to run. The response to the suggestion is platform specific.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Whatever doesn't kill us ...<br />Is probably circling back for another try.<br />SCJP 1.4
Originally posted by Shishio San:
Hi Dan,
I think it's much better. I was wondering though about the real exam. How should we react to such a question if nothing is mentionned about the platform's specific behavior of yield !?
Thx for your effort Dan
Causes the currently executing thread object to temporarily pause and allow other threads to execute.
Invoking the Thread.yield method is like offering a suggestion to the JVM to allow another thread to run. The response to the suggestion is platform specific.
Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Whatever doesn't kill us ...<br />Is probably circling back for another try.<br />SCJP 1.4
Trust God, but always tether your camel... to this tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|