From 8248f31b20dd467c0a67606d7bfb791cc86aba6a Mon Sep 17 00:00:00 2001 From: Jeremy Long Date: Mon, 2 Dec 2013 09:10:12 -0500 Subject: [PATCH] limited the number of downloads that can happen at one time Former-commit-id: b8e90fd953626d6cb4a07996a59fbae7b05917eb --- .../data/update/StandardUpdateTask.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/StandardUpdateTask.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/StandardUpdateTask.java index 6197a720d..5c09fcd02 100644 --- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/StandardUpdateTask.java +++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/data/update/StandardUpdateTask.java @@ -36,6 +36,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.parsers.SAXParser; @@ -152,9 +153,10 @@ public class StandardUpdateTask { final int poolSize = (MAX_THREAD_POOL_SIZE > maxUpdates) ? MAX_THREAD_POOL_SIZE : maxUpdates; final ExecutorService executorService = Executors.newFixedThreadPool(poolSize); final Set> futures = new HashSet>(maxUpdates); - + int ctr = 0; for (NvdCveInfo cve : updateable) { if (cve.getNeedsUpdate()) { + ctr += 1; final File file1; final File file2; try { @@ -165,6 +167,20 @@ public class StandardUpdateTask { } final CallableDownloadTask call = new CallableDownloadTask(cve, file1, file2); futures.add(executorService.submit(call)); + if (ctr == 3) { + ctr = 0; + + for (Future future : futures) { + while (!future.isDone()) { + try { + Thread.sleep(1000); + } catch (InterruptedException ex) { + Logger.getLogger(StandardUpdateTask.class.getName()).log(Level.FINE, null, ex); + } + } + } + + } } }