File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread ques

 
Swati Gupta
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Swati Gupta
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Swati Gupta
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I understand that its is java which looks for same priority but actually it depends on OS
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic