• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread ques

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now I understand that its is java which looks for same priority but actually it depends on OS
reply
    Bookmark Topic Watch Topic
  • New Topic