解释如下代码 if (emailConfigList.size() == 0) return 0; int requestCount = (emailConfigList.size() + EACH_THREAD_USER_SIZE - 1) / EACH_THREAD_USER_SIZE; ListeningExecutorService executorService = MoreExecutors.listeningDecorator(threadPoolTaskExecutor.getThreadPoolExecutor()); List<ListenableFuture<Integer>> futureList = new ArrayList<>(); for (int i = 0; i < requestCount; i++) { int current = i; futureList.add( executorService.submit(() -> { List<EmailConfig> temp; int start = current * EACH_THREAD_USER_SIZE; int end; if (current < requestCount - 1) { end = (current + 1) * EACH_THREAD_USER_SIZE; } else { end = emailConfigList.size(); } logger.info("执行用户index从:"+start+"到"+(end - 1)); temp = emailConfigList.subList(start, end); return executeForManyUser(temp, now); }) ); }
时间: 2023-06-05 09:04:19 浏览: 201
FCFS.zip_C语言FCFS调度
这段代码的作用是根据邮件配置列表的大小,将配置均分到多个线程中进行处理。其中,变量EACH_THREAD_USER_SIZE是每个线程处理的配置数量。通过线程池的方式,将处理结果封装成ListenableFuture对象进行返回。
阅读全文