网站服务费怎么做凭证,微网站建设完不知道怎么推广咋办,上海专业优化排名工具,十堰专业网站建设通过对业务逻辑的分析#xff0c;进行编码#xff0c;先把第一条sql查出来的数据进行分组#xff0c;然后分别使用不同的线程去查询数据返回#xff0c;并添加到原来的数据中。
总感觉哪里写的不对#xff0c;但是同事们都没用过这个#xff0c;请大家指教一下#xff…通过对业务逻辑的分析进行编码先把第一条sql查出来的数据进行分组然后分别使用不同的线程去查询数据返回并添加到原来的数据中。
总感觉哪里写的不对但是同事们都没用过这个请大家指教一下先谢谢了。
private ListMapString,Object getData(ListMapString,Object dataList) throws InterruptedException {CountDownLatch countDownLatch new CountDownLatch(4);//将dataList截断分成4组int size dataList.size();int groupCount size / 4;ListMapString,Object dataList1 new ArrayList(dataList.subList(0, groupCount));ListMapString,Object dataList2 new ArrayList(dataList.subList(groupCount, groupCount*2));ListMapString,Object dataList3 new ArrayList(dataList.subList(groupCount*3, groupCount*4));ListMapString,Object dataList4 new ArrayList(dataList.subList(groupCount*4, size));ThreadPoolExecutor poolExecutor creatThread(getData, 4);threadTask(poolExecutor,dataList1,countDownLatch);threadTask(poolExecutor,dataList2,countDownLatch);threadTask(poolExecutor,dataList3,countDownLatch);threadTask(poolExecutor,dataList4,countDownLatch);while (countDownLatch.getCount() ! 0){countDownLatch.await();}dataList.clear();ListMapString,Object newDataList new ArrayList();newDataList.addAll(dataList1);newDataList.addAll(dataList2);newDataList.addAll(dataList3);newDataList.addAll(dataList4);return newDataList;}
具体逻辑代码 private void threadTask(ThreadPoolExecutor threadPoolExecutor,final ListMapString,Object dataList,final CountDownLatch countDownLatch){CallableListMapString,Object getDatanew CallableListMapString, Object() {Overridepublic ListMapString, Object call() {for (MapString, Object stringObjectMap : dataList) {//执行的方法}countDownLatch.countDown();return dataList;}};FutureTaskListMapString,Object getDataTask new FutureTask(getData);threadPoolExecutor.execute(getDataTask);}
这里还是用原生的方法没有使用lambda因为服务器上的Jdk不确定是7还是8上次有同事使用了stream去处理list结果项目跑不下去被投诉了。
请各位大神不吝赐教小白在此谢过了。