多线程分批处理数据

public class DySchedule {
    private static AtomicInteger line = new AtomicInteger(0);
    static ExecutorService pool = Executors.newFixedThreadPool(100);

    public static int getLine(){
        return line.addAndGet(1000);
    }
    public static void doJob(){
        for (int i = 0;i<100;i++){
            Thread thread = new MyThread();
            pool.execute(thread);
        }
        pool.shutdown();

    }
    public static void main(String[] args) {
        DySchedule.doJob();
    }
}

public class MyThread extends Thread {
    @Override
    public void run() {
        System.out.println("线程:" + Thread.currentThread().getName());
        Integer num = DySchedule.getLine();
        System.out.println("startline = " +(num-1000)+",endline = " + num);
    }
}
posted @ 2021-07-01 17:41  王岳阳  阅读(314)  评论(0编辑  收藏  举报