cloud异步

This commit is contained in:
lushunming 2025-12-13 09:11:08 +08:00
parent d280d770bb
commit d1bb29a314
1 changed files with 41 additions and 39 deletions

View File

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