//List集合
final List plyVO = plyDayListDao.selectPlyDayListKey(dataSumNo,sd,tstate);
if(plyVO != null && plyVO.size() > 0){
//创建一个线程池
try {
int threadNum = 10;//线程数自定义
int threadSize = plyVO.size()/threadNum;//给每个线程分发处理条数(总条数/线程数);
ExecutorService eService = Executors.newFixedThreadPool(threadNum);//创建线程池
List> cList = new ArrayList>();
Callable task = null;
List sList = null;
for(int i=0;i
if(i == threadNum - 1){
sList = plyVO.subList(i*threadSize, plyVO.size());
} else {
sList = plyVO.subList(i*threadSize, (i+1)*threadSize);
}
final List nowList = sList;
task = new Callable() {
@Override
public String call() throws Exception {
StringBuffer sb = new StringBuffer();
for(int j=0;j
//处理需要处理的业务
int s = plyDayService.nvhlInsuranceResponse(nowList.get(j));
sb.append(s+"_");
}
//返回处理的结果集
return sb.toString();
}
};
cList.add(task);
}
List> results;
results = eService.invokeAll(cList);
for(Future str:results){
//打印结果集
log.info(str.get());
}
eService.shutdown();
} catch (Exception e) {
e.printStackTrace();
}
}
如果觉得《java 多线程数据分发_多线程分发处理List集合数据》对你有帮助,请点赞、收藏,并留下你的观点哦!