public class test32 { public static void main ( String [] args ){ Thread xc13 = new Thread ( new Xc44 ()); Thread xc14 = new Thread ( new Xc44 ()); xc13 . setName ( "线程一" ); xc14 . setName ( "线程二" ); xc13 . start (); xc14 . star
public static void main(String[] args){
Thread xc13=new Thread(new Xc44());
Thread xc14=new Thread(new Xc44());
xc13.setName("线程一");
xc14.setName("线程二");
xc13.start();
xc14.start();
}
}
class Xc44 implements Runnable {
public void run(){
for (int i=0;i<30;i++){
System.out.println(Thread.currentThread().getName()+""+i);
if(i%5==0){
Thread.yield();//执行到5的倍数就出去
}
}
}
}
运行结果