Commit 7d5c94f5 authored by jim's avatar jim

join

parent f445ab26
...@@ -107,9 +107,10 @@ public class BrowserTask { ...@@ -107,9 +107,10 @@ public class BrowserTask {
long time = Instant.now().minusSeconds(300).toEpochMilli(); long time = Instant.now().minusSeconds(300).toEpochMilli();
List<IpResource> ipResources = ipResourceRepository.sampleTasks(6, time); List<IpResource> ipResources = ipResourceRepository.sampleTasks(6, time);
log.error("buyIpTasks sample {} tasks", ipResources.size()); log.error("buyIpTasks sample {} tasks", ipResources.size());
List<CompletableFuture> futureList = new ArrayList<>();
for (IpResource ipResource : ipResources) { for (IpResource ipResource : ipResources) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
CompletableFuture.runAsync(() -> { CompletableFuture future = CompletableFuture.runAsync(() -> {
if (ipResourceRepository.lockTask(ipResource)) { if (ipResourceRepository.lockTask(ipResource)) {
try { try {
boolean result = false; boolean result = false;
...@@ -182,7 +183,9 @@ public class BrowserTask { ...@@ -182,7 +183,9 @@ public class BrowserTask {
} }
} }
}, ThreadPoolUtils.buyIpTasksPool); }, ThreadPoolUtils.buyIpTasksPool);
futureList.add(future);
} }
CompletableFuture.allOf(futureList.toArray(new CompletableFuture[0])).join();
} }
@Scheduled(cron = "0 0/1 * * * ?") @Scheduled(cron = "0 0/1 * * * ?")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment