File size: 926 Bytes
0284885 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | package Thread_case2_package;
import java.util.ArrayList;
import java.util.Collections;
public class MyThread extends Thread {
//集合:{10,5,20,50,100,200,500,800,2,80,300,700}
ArrayList<Integer> list;
public MyThread(ArrayList<Integer> list) {
this.list = list;
}
@Override
public void run() {
while (true) {
synchronized (MyThread.class) {
if (list.size() == 0) {
break;
} else {
//继续抽奖
Collections.shuffle(list);
Integer prize = list.remove(0);
System.out.println(getName() + "又产生了一个" + prize + "元大奖");
}
}
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
|