网站图片太多怎么办,做第一个php网站,区块链交易网站建设,网站规划网站建设报价表CompletableFuture实战 前言 前言
过去的一年#xff0c;匆匆忙忙#xff0c;换了一次工作#xff0c;写博客的习惯就落下了#xff0c;总之#xff0c;有点懈怠。希望今年能重拾信心#xff0c;步入正规#xff01;
CompletableFuture的用法网上资料颇多#xff0c;… CompletableFuture实战 前言 前言
过去的一年匆匆忙忙换了一次工作写博客的习惯就落下了总之有点懈怠。希望今年能重拾信心步入正规
CompletableFuture的用法网上资料颇多我这里就简单记录下自己项目中的真实场景代码模拟思路算是抛砖引玉~ public void handleUserList(ListUsers userList) {// 增加自定义线程池ExecutorService executorService new ThreadPoolExecutor(2, 2, 0, TimeUnit.SECONDS, new LinkedBlockingDeque(12));ListUsers itDeptList userList.stream().filter(name - name.getDeptName().equals(IT)).collect(Collectors.toList());if (CollectionUtils.isEmpty(itDeptList)) {return;}CompletableFutureVoid createFuture CompletableFuture.runAsync(() - {// 模拟某线程执行业务比如创建用户usersMapper.insert(itDeptList.get(0));}, executorService);CompletableFutureVoid updateFuture CompletableFuture.runAsync(() - {ListInteger userIds itDeptList.stream().map(Users::getUserId).collect(Collectors.toList());// 模拟某线程执行业务比如根据ID列表查询用户usersMapper.selectBatchIds(userIds);}, executorService);// 等待两个线程执行完毕最后执行主线程CompletableFuture.allOf(createFuture, updateFuture).join();}