class MyThread implements Runnable{
int i = 100;
public void run(){
while(true){
synchronized(this){
//Thread.currentThread()获得当前代码在哪一个线程中运行,会返回线程对象(Thread对象)
System.out.println(Thread.currentThread().getName() + i);
i--;
//让线程让出CPU,使所有线程重新竞争CPU
Thread.yield();
if(i<0)
break;
}
}
}
}class MyThread implements Runnable{
int i = 100;