62,614
社区成员
发帖
与我相关
我的任务
分享
public class Test {
private static Integer total = 20;
public static void main(String[] args) {
System.out.println("目前总工作量"+total+"份,请输入工作人数:");
Scanner scanner = new Scanner(System.in);
Integer persons = scanner.nextInt();
int var0 = total/persons;
for(int i=0;i<persons;i++){
new Thread(new Woker(var0,"Thread-"+i)).start();
}
}
}
class Woker implements Runnable{
private Integer total;
private String wokerName;
public Woker(Integer total, String wokerName) {
this.total = total;
this.wokerName = wokerName;
}
@Override
public void run(){
for(int i = 0;i<total;i++){
System.out.println(wokerName+"正在开始任务"+i);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(wokerName+"已经完成任务"+i);
}
}
}