|
|
|
|
@ -283,26 +283,33 @@ public class GreenTrafficServiceImpl implements IGreenTrafficService {
|
|
|
|
|
int taskCount = 5; // 任务数量
|
|
|
|
|
|
|
|
|
|
//定义是第几次取
|
|
|
|
|
int times = 1;
|
|
|
|
|
int round = 1;
|
|
|
|
|
|
|
|
|
|
//是否停止线程
|
|
|
|
|
boolean isStop = true;
|
|
|
|
|
|
|
|
|
|
//一直循环取,直到取到空就停止
|
|
|
|
|
while(isStop){
|
|
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(taskCount); // 同步工具
|
|
|
|
|
|
|
|
|
|
//定义每一轮 取到第几条结束
|
|
|
|
|
int getOver = times*taskCount;
|
|
|
|
|
logger.info("取图片轮次=======round======="+round);
|
|
|
|
|
|
|
|
|
|
//定义每一轮 取的时候从第几个下标开始取
|
|
|
|
|
int position = ((times-1)*taskCount)+1;
|
|
|
|
|
//定义同步工具,每轮五个线程
|
|
|
|
|
CountDownLatch countDownLatch = new CountDownLatch(5); // 同步工具
|
|
|
|
|
|
|
|
|
|
//定义每一轮 取到第几条结束 5 10 15
|
|
|
|
|
int getOver = round*taskCount;
|
|
|
|
|
|
|
|
|
|
//定义每一轮 取的时候从第几个下标开始取 1 6 11
|
|
|
|
|
int position = ((round-1)*taskCount)+1;
|
|
|
|
|
|
|
|
|
|
//循环开启5个线程取图片
|
|
|
|
|
for (int i = position ; i <= getOver;i++) {
|
|
|
|
|
|
|
|
|
|
//拼接参数
|
|
|
|
|
Map<String, Object> paramsWebService = new HashMap<>();
|
|
|
|
|
paramsWebService.put("listNO", params.get("listNo")+"_"+i);
|
|
|
|
|
paramsWebService.put("imgType", "1");
|
|
|
|
|
//执行线程
|
|
|
|
|
greenTrafficThreadPool.execute( () -> {
|
|
|
|
|
try {
|
|
|
|
|
picList.add(getPic(paramsWebService));
|
|
|
|
|
@ -310,12 +317,14 @@ public class GreenTrafficServiceImpl implements IGreenTrafficService {
|
|
|
|
|
logger.info("获取图片失败========"+e);
|
|
|
|
|
picList.add("");
|
|
|
|
|
}
|
|
|
|
|
//执行完同步工具值减1
|
|
|
|
|
countDownLatch.countDown();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//等待子线程执行完毕
|
|
|
|
|
countDownLatch.await();
|
|
|
|
|
logger.info("主线程工作结束==============");
|
|
|
|
|
|
|
|
|
|
logger.info("主线程工作结束==============");
|
|
|
|
|
|
|
|
|
|
//遍历数据,是否有空,有空就停止执行
|
|
|
|
|
for (String pic : picList) {
|
|
|
|
|
@ -324,9 +333,12 @@ public class GreenTrafficServiceImpl implements IGreenTrafficService {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
times++;
|
|
|
|
|
//轮次加1
|
|
|
|
|
round++;
|
|
|
|
|
logger.info("是否停止取图片=======isStop======="+isStop);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//封装数据,为空的跳过
|
|
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
|
|
for (String picUrl : picList) {
|
|
|
|
|
if(!"".equals(picUrl)){
|
|
|
|
|
|