Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Marcus Green mock exam - 2 #24 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 "Marcus Green mock exam - 2 #24" Watch "Marcus Green mock exam - 2 #24" New topic
Author

Marcus Green mock exam - 2 #24

Savio Mascarenhas
Ranch Hand

Joined: Nov 29, 2000
Posts: 108
Question 24)
Under what circumstances might you use the yield method of the Thread class
1) To call from the currently running thread to allow another thread of the same or higher priority to run
2) To call on a waiting thread to allow it to run
3) To allow a thread of higher priority to run
4) To call from the currently running thread with a parameter designating which thread should be allowed to run

The answer mentioned was (1).Is (1) fine ???.
Suppose when yield() is executed ,there is only one "lower priority thread" that is in the ready state . In such a case won'nt that thread run,irrespective of what priority it holds .
Pls give ur opinion .
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
If that's the case, the thread that issued the yield call will immediately continue executing. This might even depend on the thread scheduler.
Bosun


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Michael Burke
Ranch Hand

Joined: Jul 29, 2000
Posts: 103
I also think #3 is a correct answer, any comments?
shree vijay
Ranch Hand

Joined: Sep 18, 2000
Posts: 208
Originally posted by Savio Mascarenhas:
Question 24)
Under what circumstances might you use the yield method of the Thread class
1) To call from the currently running thread to allow another thread of the same or higher priority to run
2) To call on a waiting thread to allow it to run
3) To allow a thread of higher priority to run
4) To call from the currently running thread with a parameter designating which thread should be allowed to run

The answer mentioned was (1).Is (1) fine ???.
Suppose when yield() is executed ,there is only one "lower priority thread" that is in the ready state . In such a case won'nt that thread run,irrespective of what priority it holds .
Pls give ur opinion .

The answer is obviously 1
1. whenever you call yield, you call it for the currently executing thread only. Once this thread yields, it will quit the running state and reach the ready state. So any thread that is in the ready state which has the same priority or higher priority will take over the CPU.
2. false. the yield() method does not take any parameters. So, it cannot call any other thread like yield(t). Also, if the thread t1 is running, you cannot have a statement t2.yield() within the run of t1. You can just have yield() which means, that thread whose run is being executed(t1 in this case) has decided to yield on its own ( some kind-heartedness that )
3. false. When a thread yields, the new thread that takes over
need not always have a higher priority. It may be an equal priority thread also.
4. false -- as given in explanation of option 2
Regarding your final question, i think what you say is true. If the waiting thread is of a lower priority, if it is the only thread -- the process should be the current thread yields, goes to the ready state and then comes back to the running state.
Guess somebody more knowledgable regarding threads can ascertain that. Or probably we can try it with a program.
Hope this helps.
------------------
Regards,
Shree
[This message has been edited by shree vijay (edited December 09, 2000).]


Regards,<BR>Shree
 
Consider Paul's rocket mass heater.
 
subject: Marcus Green mock exam - 2 #24