Multithreading best practices : constraining tasks newFixedThreadPool

前端 未结 5 1172
执笔经年
执笔经年 2021-01-15 01:31

I want to launch a lot of tasks to run on a database of +-42Mio records. I want to run this in batches of 5000 records/time (results in 850 tasks). I also want to limit the

5条回答
  •  难免孤独
    2021-01-15 01:58

    Changed from your code:

        ExecutorService executorService = Executors.newFixedThreadPool(16);
        for (int j = 1; j < 900 + 1; j++) {
            int start = (j - 1) * 5000;
            int stop = (j) * 5000 - 1;
            FetcherRunner runner = new FetcherRunner(routes, start, stop);
            executorService.submit(runner);
    
        }
    

提交回复
热议问题