谁帮忙看看为什么这个代码没有任何输出啊...???
public class HomeWork9 {
public static void main(String[] args) {
AddData ad = new AddData();
Thread t1 = new Thread(ad);
Thread t2 = new Thread(ad);
t1.setName("线程1");
t2.setName("线程2");
t1.start();
t2.start();
}
}
class AddData implements Runnable{
private int[] arr = new int[12];
@Override
public void run() {
while(true){
if(arr.length >= 12){
break;
}
for (int i = 0; i < 12; i++) {
if(i % 3 == 0){
Thread.yield();
}
arr[i] = (int)(Math.random()*100);
System.out.println(Thread.currentThread().getName() + "..." + arr[i]);
}
}
}
} |
|