当前位置:网站首页>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("无资源");
}
边栏推荐
- Taobao product details API interface
- 【LeetCode每日一题】——844.比较含退格的字符串
- Tidb二进制集群搭建
- Multiscale communication in cortical-cortical networks
- 软件测试主要做什么工作,难不难?
- How to choose professional, safe and high-performance remote control software
- 拼多多API接口(附上我的可用API)
- 梅科尔工作室——BP神经网络
- sql--7天内(含当天)购买次数超过3次(含),且近7天的购买金额超过1000的用户
- 【软件测试】(北京)字节跳动科技有限公司二面笔试题
猜你喜欢
Douyin share password url API tool
3GPP LTE/NR信道模型
实现通用的、高性能排序和快排优化
Shell:三剑客之awk
Spatial Pyramid Pooling -Spatial Pyramid Pooling (including source code)
Implement general-purpose, high-performance sorting and quicksort optimizations
Pinduoduo api interface application example
从苹果、SpaceX等高科技企业的产品发布会看企业产品战略和敏捷开发的关系
Taobao API interface reference
Redis源码-String:Redis String命令、Redis String存储原理、Redis字符串三种编码类型、Redis String SDS源码解析、Redis String应用场景
随机推荐
maxwell concept
Daily sql - judgment + aggregation
MySQL 版本升级心得
为什么我使用C#操作MySQL进行中文查询失败
【LaTex-错误和异常】\verb ended by end of line.原因是因为闭合边界符没有在\verb命令所属行中出现;\verb命令的正确和错误用法、verbatim环境的用法
C语言每日一练——Day02:求最小公倍数(3种方法)
easyrecovery15数据恢复软件收费吗?功能强大吗?
Redis源码-String:Redis String命令、Redis String存储原理、Redis字符串三种编码类型、Redis String SDS源码解析、Redis String应用场景
Implement general-purpose, high-performance sorting and quicksort optimizations
js根据当天获取前几天的日期
【软件测试】(北京)字节跳动科技有限公司二面笔试题
微信小程序功能上新(2022.06.01~2022.08.04)
JD.com product details API call example explanation
Douyin API interface
prometheus学习5altermanager
为什么C#中对MySQL不支持中文查询
每日sql--统计员工近三个月的总薪水(不包括最新一个月)
软件测试主要做什么工作,难不难?
daily sql - user retention rate for two days
伦敦银规则有哪些?