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

Thread ques

Swati Gupta
Ranch Hand

Joined: May 28, 2002
Posts: 106
There is a question from mock exam and the right answer is:--
The yield() method is called to take a thread out of the running state and place it into the runnable pool to allow threads of the same priority to start.
Is the above explanation is right?
I thought the thread schedular will decide which thread to run.and once a thread will call the yield() method any other thread or the same thread can run.
[ June 03, 2002: Message edited by: swati gupta ]
Thomas Kijftenbelt
Ranch Hand

Joined: Feb 13, 2002
Posts: 73
Hi,
I would say the answer is correct:
The yield() method is called to take a thread out of the running state and place it into the runnable pool to allow threads of the same priority to start.
And the decission which thread will be put in the running state is made by the thread scheduler... if there is no other thread, the thread calling yield will most probably be put back in the running state again.
Greetings,
TK
SCJP
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
Originally posted by swati gupta:
The yield() method is called to take a thread out of the running state and place it into the runnable pool to allow threads of the same priority to start.
Is the above explanation is right?


It is correct except for the priority part. Since we know nothing about the scheduler, we can say nothing about the priority of the new thread selected to run.
So the statement should be

The yield() method is called to take a thread out of the running state and place it into the runnable pool to allow other threads to run.


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Swati Gupta
Ranch Hand

Joined: May 28, 2002
Posts: 106
quote:
The yield() method is called to take a thread out of the running state and place it into the runnable pool to allow threads of the same priority to start.
I have come across this line at other palces also.
But even I thing that the yield()method is used to that the low priority threads do not starve.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by swati gupta:
quote:
The yield() method is called to take a thread out of the running state and place it into the runnable pool to allow threads of the same priority to start.
I have come across this line at other palces also.
But even I thing that the yield()method is used to that the low priority threads do not starve.

Indeed, you shouldn't create a thread that sucks up gobs of processing power without giving it up. Doing so it almost bound to make your system unresponsive and painful to use. Rather, if you have a large amount of processing to do, it is wise to invoke the yield method to allow other threads to perform their tasks, as well.
However, which thread actually gets to run is up to the underlying OS. Java may have intended for yield to allow other threads of the same priority to execute, but that's not up to Java to decide. They can only make a recommendation. The underlying OS has the final decision in the matter.
I hope that helps,
Corey


SCJP Tipline, etc.
Swati Gupta
Ranch Hand

Joined: May 28, 2002
Posts: 106
Now I understand that its is java which looks for same priority but actually it depends on OS
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread ques