Thread (四)线程让步

package com.dragon.test4;
/**
* 线程让步
* @author Administrator
*
*/
public class Test {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
FirstThread firstThread = new FirstThread();
SecondThread secondThread = new SecondThread();
ThirdThread thirdThread= new ThirdThread();
firstThread.start();
secondThread.start();
thirdThread.start();
}

}
/**
* 创建第一个线程
* @author Administrator
*
*/
class FirstThread extends Thread{
public void run(){
for (int i = 0; i < 5; i++) {
System.out.println("第一个线程第"+i+"次循环");
}

}
}
/**
* 第二个线程
* @author Administrator
*
*/
class SecondThread extends Thread{
public void run(){
for (int i = 0; i < 5; i++) {
System.out.println("第二个线程第"+i+"次循环");
Thread.yield();//线程让步

}

}
}
/**
* 第三个线程
* @author Administrator
*
*/
class ThirdThread extends Thread{
public void run(){
for (int i = 0; i < 5; i++) {
System.out.println("第三个线程第"+i+"次循环");
}

}
}

 <wbr></wbr>
 

你可能感兴趣的:(thread)