当前位置:网站首页>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("无资源");
}
边栏推荐
- LeetCode刷题系列 -- 46. 全排列
- js根据当天获取前几天的日期
- 淘宝商品详情API接口
- sql--7天内(含当天)购买次数超过3次(含),且近7天的购买金额超过1000的用户
- concept noun
- redis + lua实现分布式接口限流实现方案
- Daily sql-statistics of the number of professionals (including the number of professionals is 0)
- 【Pytorch】nn.PixelShuffle
- 【@网络工程师:用好这6款工具,让你的工作效率大翻倍!】
- 技术分享 | 实战演练接口自动化如何处理 Form 请求?
猜你喜欢

Resolved EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo

exness:黄金1800关口遇阻,静待美国CPI出炉

jar服务导致cpu飙升问题-带解决方法

ssh服务攻防与加固

STM32CUBEIDE(11)----输出PWM及修改PWM频率与占空比

unable to extend table xxx by 1024 in tablespace xxxx

拼多多API接口(附上我的可用API)

Daily sql-seek the sum of successful investments in 2016

拼多多API接口大全

进制转换间的那点事
随机推荐
Daily sql--statistics the total salary of employees in the past three months (excluding the latest month)
每日sql-员工奖金过滤和回答率排序第一
如何选择专业、安全、高性能的远程控制软件
PIXHAWK飞控使用RTK
Douyin get douyin share password url API return value description
【LaTex-错误和异常】\verb ended by end of line.原因是因为闭合边界符没有在\verb命令所属行中出现;\verb命令的正确和错误用法、verbatim环境的用法
【Pytorch】nn.ReLU(inplace=True)
Implementation of FIR filter based on FPGA (5) - FPGA code implementation of parallel structure FIR filter
mysql视图与索引
When MySQL uses GROUP BY to group the query, the SELECT query field contains non-grouping fields
2022-08-09 Group 4 Self-cultivation class study notes (every day)
进制转换间的那点事
LeetCode brushing series -- 46. Full arrangement
How to choose professional, safe and high-performance remote control software
常见激活函数及其导数
【预约观看】Ambire 智能钱包 AMA 活动第四期即将举行
Daily sql: request for friend application pass rate
matplotlib
已解决EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo
What are the things that should be planned from the beginning when developing a project with Unity?How to avoid a huge pit in the later stage?