/**
* A hint to the scheduler that the current thread is willing to yield
* its current use of a processor. The scheduler is free to ignore this
* hint.
*
* <p> Yield is a heuristic attempt to improve relative progression
* between threads that would otherwise over-utilise a CPU. Its use
* should be combined with detailed profiling and benchmarking to
* ensure that it actually has the desired effect.
*
* <p> It is rarely appropriate to use this method. It may be useful
* for debugging or testing purposes, where it may help to reproduce
* bugs due to race conditions. It may also be useful when designing
* concurrency control constructs such as the ones in the
* {@link java.util.concurrent.locks} package.
*/
public static native void yield();
向调度器暗示当前线程愿意放弃当前对处理器的使用。调度器可以忽略这个提示。
Yield是一种启发式尝试,旨在改善线程之间的相对进程,否则会过度使用CPU。它的使用应该与详细的分析和基准测试相结合,以确保它实际上具有预期的效果。
使用这种方法很少是合适的。它可能用于调试或测试目的,在这些目的中,它可能有助于由于竞争条件而重新生成错误。在设计并发控制构造(如java.util.concurrent.locks包中的构造)时,它可能也很有用。