aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes yield 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 "yield" Watch "yield" New topic
Author

yield

Charlie Swanson
Ranch Hand

Joined: Jan 29, 2001
Posts: 213
I would very much appreciate your help with the following? I am confused on this.
With the yield method, is it true a job can be holding back a job
with the same priority and lower priority?
Also, if the priority of jobs is based on time slicing what would happen to the yield method? What would happen if it was
a time-slicing mechanism and different priorities existed?
What is the correct answer below, and why or why not?
Which statement about scheduling thread execution is true?
a The wait() method is called to place a thread at the back of
the runnable pool to allow threads of a lower priority to start.
b The yield() method is called to place a thread at the back of the runnable pool to allow threads of a lower priority to start
c The wait() method is called to place a thread at the back of
the runnable pool to allow thread of the same priority to
start
d The yield method is called to take a thread out of the running state and place into the runnable pool to allow threads
of the same priority to start
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Originally posted by Charlie Swanson:

With the yield method, is it true a job can be holding back a job
with the same priority and lower priority?

The currently executing thread can hold back a thread of equal or lower priority.

Also, if the priority of jobs is based on time slicing what would happen to the yield method?

On a time sliced OS the yield() method will still function correctly. It would just preempt the OS and stop one thread from running and let another of equal priority run. It is a good idea to use yield() just so your code is truly portable, if you don't use yield and your code is run on a non-time sliced machine then the first thread will run to completion (unless a higher priority thread comes along).

What would happen if it was
a time-slicing mechanism and different priorities existed?

Time-slicing will only effect threads of the same priority (as will yield()). On a time sliced machine if there are multiple threads of the same priority and none of a higher priority then the OS will schedule each thread with the same priority a certain portion of processor time. Any threads of lower priority will have to wait until all of the higher ones are done (or are all not runnable for some reason). And any thread of a higher priority would have taken over anyway.

What is the correct answer below, and why or why not?
Which statement about scheduling thread execution is true?
a The wait() method is called to place a thread at the back of
the runnable pool to allow threads of a lower priority to start.
b The yield() method is called to place a thread at the back of the runnable pool to allow threads of a lower priority to start
c The wait() method is called to place a thread at the back of
the runnable pool to allow thread of the same priority to
start
d The yield method is called to take a thread out of the running state and place into the runnable pool to allow threads
of the same priority to start

correct answer would be d.
a and c are wrong because wait() doesn't neccesarily move a thread back to the end of the line. When notify() or notifyAll() is called any waiting thread could be chosen to run. Also, (I could be wrong here - someone let me know if I am) I don't think that just calling wait() will let other threads of the same priority run unless you also call notify() or notifyAll().
b is wrong because yield() lets equal priority threads run not lower priority. If the only other threads are of lower priority the the thread that called yield() will start running again right away.
hope that helped
Dave


Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: yield