java大数据量处理-多线程的使用
场景: 处理大量数据的 update 或 insert 操作时 需要借助多线程的处理来缩短处理时间
代码示例:
List<List<T>> partitionDataList = Lists.partition(vos, maxRead);
//定义线程池个数
Integer writeThreadCount = 1;
//创建线程池
ExecutorService executorService = Executors.newFixedThreadPool(writeThreadCount);
for(List<PowerInfoVO> data : partitionDataList){
executorService.submit(() -> {
//需要多线程处理的逻辑
});}
// 关闭线程池
executorService.shutdown();
// 等待所有任务执行完毕
try {
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch (InterruptedException e){
//处理超时
}

浙公网安备 33010602011771号