属于本地方法

    /**
     * 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();

 当前线程愿意放弃当前的CPU,但是调度程序可以忽略这一意愿,所以当线程执行了yield()方法后不一定就从running进入到ruunable状态。

 

相关文章:

  • 2022-02-04
  • 2021-12-20
  • 2021-07-13
  • 2021-09-24
  • 2021-05-24
  • 2021-12-09
  • 2022-03-08
猜你喜欢
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
  • 2021-07-01
  • 2021-05-17
  • 2021-08-28
相关资源
相似解决方案