• Post Reply Bookmark Topic Watch Topic
  • New Topic

Yield in Thread  RSS feed

 
Vivek Nidhi
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I know that yield() is not a guaranteed behaviour. But it is guranteed to move the current threads from running state to runnable state.
will this happen in all sorts of JVMs. I know this will happen in case if preemptive scheduling is supported. Will this happen if the OS is time-sclice

regs
Vivek Nidhi
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Javadoc says


Causes the currently executing thread object to temporarily pause and allow other threads to execute.


That's what it does.
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When a thread is created, it inherits its priority from the thread that created it. You also can modify a thread's priority at any time after its creation by using the setPriority method. Thread priorities are integers ranging between MIN_PRIORITY and MAX_PRIORITY (constants defined in the Thread class). The higher the integer, the higher the priority. At any given time, when multiple threads are ready to be executed, the runtime system chooses for execution the Runnable thread that has the highest priority. Only when that thread stops, yields, or becomes Not Runnable will a lower-priority thread start executing. If two threads of the same priority are waiting for the CPU, the scheduler arbitrarily chooses one of them to run. The chosen thread runs until one of the following conditions is true:

* A higher priority thread becomes runnable.
* It yields, or its run method exits.
* On systems that support time-slicing, its time allotment has expired.

Then the second thread is given a chance to run, and so on, until the interpreter exits.

The Java Tutorial: Thread Scheduling
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
its possible yielding will prematurely end the given threads slice. Depends on the OS/JVM.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!