feat: download concurrency settings. Closes #990.

This commit is contained in:
huanghongxun
2021-09-03 03:14:39 +08:00
parent b3d083877f
commit 243c9b83b9
11 changed files with 214 additions and 11 deletions

View File

@@ -268,8 +268,9 @@ public abstract class FetchTask<T> extends Task<T> {
}
private static int downloadExecutorConcurrency = Math.min(Runtime.getRuntime().availableProcessors() * 4, 64);
private static volatile ExecutorService DOWNLOAD_EXECUTOR;
public static int DEFAULT_CONCURRENCY = Math.min(Runtime.getRuntime().availableProcessors() * 4, 64);
private static int downloadExecutorConcurrency = DEFAULT_CONCURRENCY;
private static volatile ThreadPoolExecutor DOWNLOAD_EXECUTOR;
/**
* Get singleton instance of the thread pool for file downloading.
@@ -292,8 +293,8 @@ public abstract class FetchTask<T> extends Task<T> {
synchronized (Schedulers.class) {
downloadExecutorConcurrency = concurrency;
if (DOWNLOAD_EXECUTOR != null) {
DOWNLOAD_EXECUTOR.shutdownNow();
DOWNLOAD_EXECUTOR = null;
DOWNLOAD_EXECUTOR.setCorePoolSize(concurrency);
DOWNLOAD_EXECUTOR.setMaximumPoolSize(concurrency);
}
}
}