java多线程实战四:自定义线程池实现多线程任务处理
这里多线程处理excel批量数据导入功能,
1、首先将业务数据分成5批
2、ThreadPoolExecutor创建线程池,分5个运行,存活时间3分钟
3、将RequestAttributes对象设置为子线程共享
4、多线程处理任务
5、等待所有任务执行完成且等待队列中也无任务关闭线程池
poolExecutorVerify.shutdown();
6、 阻塞主线程, 直至线程池关闭
poolExecutorVerify.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS)
//将此次要导入的数据分批 分5批
List<List<StudentImportModelExcel>> studentLists = ListUtil.averageAssign(data,5);
//创建线程池 分5个运行 存活时间3分钟
ThreadPoolExecutor poolExecutorVerify = new ThreadPoolExecutor(5, 5, 3, TimeUnit.MINUTES, new