当前位置:网站首页>2021-08-11 for循环结合多线程异步查询并收集结果
2021-08-11 for循环结合多线程异步查询并收集结果
2022-08-11 06:44:00 【yy1209357299】
JsonResult jsonResult = new JsonResult();
ExecutorService executorService = Executors.newCachedThreadPool();
HashMap<String,String> map = new HashMap<>();
for(int i=0;i<jsonArray.size();i++){
final int j = i;
executorService.execute(new Runnable() {
@Override
public void run() {
synchronized (this){
String name = jsonArray.getJSONObject(j).getString("1");
String id = jsonArray.getJSONObject(j).getString("2");
String url = null;
try {
url = getUrl(id);
} catch (Exception e) {
e.printStackTrace();
}
map.put(name,url);
}
}
});
}
executorService.shutdown();
while(true){
if(executorService.isTerminated()){
break;
}
}
if(map.size()>0){
jsonResult.setCode("200");
jsonResult.setResult(map);
}else {
jsonResult.setCode("300");
jsonResult.setResult("无资源");
}
边栏推荐
猜你喜欢
随机推荐
你是如何做好Unity项目性能优化的
亚马逊API接口大全
Douyin get douyin share password url API return value description
基于FPGA的FIR滤波器的实现(4)— 串行结构FIR滤波器的FPGA代码实现
A used in the study of EEG ultra scanning analysis process
2022-08-09 第四小组 修身课 学习笔记(every day)
Do not add the is prefix to the variables of the boolean type in the POJO class of the Alibaba specification
DDR4内存条电路设计
那些事情是用Unity开发项目应该一开始规划好的?如何避免后期酿成巨坑?
How Unity programmers can improve their abilities
详述 MIMIC护理人员信息表(十五)
Douyin share password url API tool
抖音API接口大全
拼多多API接口大全
3GPP LTE/NR信道模型
Daily sql - judgment + aggregation
拼多多API接口(附上我的可用API)
C语言每日一练——Day02:求最小公倍数(3种方法)
Taobao product details API interface
基于FPGA的FIR滤波器的实现(5)— 并行结构FIR滤波器的FPGA代码实现









