礼让线程

礼让线程 yield让出cpu

package com.loaderman.threadmethod;


public class Demo_Yield {


/**

* yield让出cpu礼让线程

*/

  public static void main(String[] args) {

    new MyThread().start();

    new MyThread().start();

  }


}


class MyThread extends Thread {

  public void run() {

    for(int i = 1; i <= 1000; i++) {

      if(i % 10 == 0) {

          Thread.yield(); //让出CPU

      }
      
    System.out.println(getName() + "..." + i);

    }
  
  }

}

 

posted on 2017-02-17 18:38  LoaderMan  阅读(352)  评论(0编辑  收藏  举报

导航