zxy0307's picture
Upload 2300 files
0284885 verified
Raw History Blame Contribute Delete
926 Bytes
package Thread_case2_package;
import java.util.ArrayList;
import java.util.Collections;
public class Test {
public static void main(String[] args) {
/*
有一个抽奖池,该奖池中存放了奖励金额,该抽奖池中的奖项为{10,5,20,50,100,200,500,800,2,80,300,700};
创建两个抽奖箱(线程)设置线程名称分别为"抽奖箱1","抽奖箱2"
随机从抽奖池中获取奖项元素并打印在控制台上
*/
//创建奖池
ArrayList<Integer> list = new ArrayList<>();
Collections.addAll(list, 10, 5, 20, 50, 100, 200, 500, 800, 2, 80, 300, 700);
//创建线程
MyThread t1 = new MyThread(list);
MyThread t2=new MyThread(list);
//设置名字
t1.setName("抽奖箱1");
t2.setName("抽奖箱2");
//启动线程
t1.start();
t2.start();
}
}