业务数是不确定的,也可将业务理解为人

解决方案 »

  1.   


    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);
            }
        }
    }