cloud异步
This commit is contained in:
parent
d280d770bb
commit
d1bb29a314
|
|
@ -130,11 +130,12 @@ public class Cloud extends Spider {
|
|||
|
||||
//同時获取from 和url ,放入缓存,只要一个函数执行就行,避免重复执行
|
||||
private void getPlayFromAndUrl(List<String> shareLinks) {
|
||||
//首先清空缓存,避免太多缓存
|
||||
ExecutorService service = Executors.newFixedThreadPool(4);
|
||||
try { //首先清空缓存,避免太多缓存
|
||||
resultMap.clear();
|
||||
List<String> urls = new ArrayList<>();
|
||||
List<String> froms = new ArrayList<>();
|
||||
ExecutorService service = Executors.newFixedThreadPool(4);
|
||||
|
||||
List<Future<ImmutablePair<String, String>>> futures = new ArrayList<>();
|
||||
int i = 0;
|
||||
for (String shareLink : shareLinks) {
|
||||
|
|
@ -165,11 +166,11 @@ public class Cloud extends Spider {
|
|||
url = pan123.detailContentVodPlayUrl(List.of(shareLink));
|
||||
from = pan123.detailContentVodPlayFrom(List.of(shareLink), finalI);
|
||||
}
|
||||
return new ImmutablePair<String, String>(url, from);
|
||||
return new ImmutablePair<>(url, from);
|
||||
}));
|
||||
|
||||
}
|
||||
try {
|
||||
|
||||
for (Future<ImmutablePair<String, String>> future : futures) {
|
||||
//只有连接不为空才放入进去
|
||||
if (StringUtils.isNoneBlank(future.get().left)) {
|
||||
|
|
@ -178,13 +179,14 @@ public class Cloud extends Spider {
|
|||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
SpiderDebug.log("获取异步结果出错:" + e);
|
||||
}
|
||||
resultMap.put(Util.MD5(Json.toJson(shareLinks)), new ImmutablePair<List<String>, List<String>>(urls, froms));
|
||||
resultMap.put(Util.MD5(Json.toJson(shareLinks)), new ImmutablePair<>(urls, froms));
|
||||
|
||||
SpiderDebug.log("---urls:" + Json.toJson(urls));
|
||||
SpiderDebug.log("---froms:" + Json.toJson(froms));
|
||||
} catch (Exception e) {
|
||||
SpiderDebug.log("获取异步结果出错:" + e);
|
||||
} finally {
|
||||
service.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue