当前位置:网站首页>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("无资源");
}
边栏推荐
- maxwell 概念
- 进制转换间的那点事
- Taobao API common interface and acquisition method
- SQL sliding window
- daily sql - user retention rate for two days
- Unity程序员如何提升自己的能力
- 接入网、承载网、核心网是什么,交换机路由器是什么、这个和网络的协议有什么关系呢?
- 2022-08-10 Group 4 Self-cultivation class study notes (every day)
- How do you optimize the performance of your Unity project?
- Daily SQL - find each of the students school gpa minimum (window)
猜你喜欢
JD.com product details API call example explanation
easyrecovery15数据恢复软件收费吗?功能强大吗?
《猪猪1984》NFT 作品集将上线 The Sandbox 市场平台
EasyPlayer针对H.265视频不自动播放设置下,loading状态无法消失的解决办法
下一代 无线局域网--强健性
伦敦银规则有哪些?
exness:黄金1800关口遇阻,静待美国CPI出炉
daily sql - query for managers and elections with at least 5 subordinates
【软件测试】(北京)字节跳动科技有限公司二面笔试题
DDR4内存条电路设计
随机推荐
2022-08-10 Group 4 Self-cultivation class study notes (every day)
Douyin API interface
JD.com product details API call example explanation
Find the shops that have sold more than 1,000 yuan per day for more than 30 consecutive days in the past six months
Unity3D learning route?
Daily sql--statistics the total salary of employees in the past three months (excluding the latest month)
LeetCode brushing series -- 46. Full arrangement
博途PLC 1200/1500PLC ModbusTcp通信梯形图优化汇总(多服务器多从站轮询)
pytorch,numpy两种方法实现nms类间+类内
从苹果、SpaceX等高科技企业的产品发布会看企业产品战略和敏捷开发的关系
语音信号处理:预处理【预加重、分帧、加窗】
daily sql - query for managers and elections with at least 5 subordinates
联想集团:2022/23财年第一季度业绩
已解决EROR 1064 (42000): You have an error in. your SOL syntax. check the manual that corresponds to yo
Redis + lua implements distributed interface current limiting implementation scheme
Daily sql: request for friend application pass rate
淘宝商品详情API接口
matplotlib
Multiscale communication in cortical-cortical networks
SQL滑动窗口