用10个一次拉2吨的卡车代替1个一次拉10吨的卡车。前提是有资源折腾,比如线程池,多核cpu,也要考虑线程的切换代价。把java服务器和数据库服务器综合利用起来,传统的方式是java服务器发送一条指令给数据库就坐等喝茶拿结果,数据库累个半死才出结果,而且出力不讨好,嫌干活慢,现在也要让java服务器也要干点事,这样大家都心里比较平衡点。

List>> allStationsTimesAmount =

inputParamArrayList.stream()

.map(inputParam -> CompletableFuture.supplyAsync(() ->nonOilSalesAndPerCustomerTransactionDao.getTimesHoursInterval(inputParam), executorService))

.collect(Collectors.toList());

List> timesAmount = allStationsTimesAmount.stream()

.map(CompletableFuture::join)

.collect(Collectors.toList());

private List getBarcodeList(String[] deptIds, String[] ids) {

List list = new ArrayList<>();

List list1 = new ArrayList<>();

if (deptIds != null){

list = Arrays.asList(deptIds);

List>> allBarcodes =

list.stream()

.map(inputParam -> CompletableFuture.supplyAsync(() ->nonOilSalesAndPerCustomerTransactionDao.getBarcodesBydeptid(inputParam), executorService))

.collect(Collectors.toList());

List> listList = allBarcodes.stream()

.map(CompletableFuture::join)

.collect(Collectors.toList());

//List> 转换为List ,使用flatMap

list1 =

listList.stream()

.flatMap(inner -> inner.stream()).collect(Collectors.toList());

}

if (ids != null){

list1.addAll(Arrays.asList(ids));

}

return list1;

}

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐