多线程分批处理数据

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);
    }
}
每天一点点,惊喜不间断
原文地址:https://www.cnblogs.com/wszn-java/p/14959951.html