当前位置:网站首页>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("无资源");
}
边栏推荐
- Trill keyword search goods - API
- Go语言实现Etcd服务发现(Etcd & Service Discovery & Go)
- golang fork 进程的三种方式
- 软件测试主要做什么工作,难不难?
- 一张图了解JVM八大原子操作
- STM32CUBEIDE(11)----输出PWM及修改PWM频率与占空比
- Waldom Electronics宣布成立顾问委员会
- 【LaTex-错误和异常】\verb ended by end of line.原因是因为闭合边界符没有在\verb命令所属行中出现;\verb命令的正确和错误用法、verbatim环境的用法
- NTT的Another Me技术助力创造歌舞伎演员中村狮童的数字孪生体,将在 “Cho Kabuki 2022 Powered by NTT”舞台剧中首次亮相
- Do not add the is prefix to the variables of the boolean type in the POJO class of the Alibaba specification
猜你喜欢

3GPP LTE/NR信道模型

抖音API接口

radix-4 FFT principle and C language code implementation

Implementation of FIR filter based on FPGA (5) - FPGA code implementation of parallel structure FIR filter

【@网络工程师:用好这6款工具,让你的工作效率大翻倍!】

淘宝商品详情API接口

Taobao API interface reference

Coordinate system in navigation and positioning

一种用于EEG超扫描研究的分析流程

每日sql-求2016年成功的投资总和
随机推荐
Unity3D learning route?
MySQL 版本升级心得
为什么C#中对MySQL不支持中文查询
pytorch,numpy两种方法实现nms类间+类内
亚马逊API接口大全
Resolved EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo
prometheus学习4Grafana监控mysql&blackbox了解
daily sql - query for managers and elections with at least 5 subordinates
How Unity programmers can improve their abilities
进制转换间的那点事
李沐d2l(十)--卷积层Ⅰ
Get Pinduoduo product information operation details
每日sql - 判断+聚合
微信小程序功能上新(2022.06.01~2022.08.04)
Redis测试
结合均线分析k线图的基本知识
STM32CUBEIDE(11)----输出PWM及修改PWM频率与占空比
ROS 服务通信理论模型
一种用于EEG超扫描研究的分析流程
opencv实现数据增强(图片+标签)平移,翻转,缩放,旋转