e***a 发帖数: 1661 | 1 what is the use of thread.yield()? | a******n 发帖数: 5925 | 2 考试书上抄来的
What yield() is supposed to do is
make the currently running thread head back to runnable to allow other
threads of
the same priority to get their turn. So the intention is to use yield() to
promote
graceful turn-taking among equal-priority threads. In reality, though, the
yield()
method isn't guaranteed to do what it claims, and even if yield() does cause
a
thread to step out of running and back to runnable, there's no guarantee the
yielding
thread won't just be chosen again over all the others! So while yield()
might—and
often does—make a running thread give up its slot to another runnable
thread of the
same priority, there's no guarantee. |
|