This commit is contained in:
huanghongxun
2020-12-21 01:56:46 +08:00
parent a828896989
commit 8bc5d2112f
2 changed files with 10 additions and 6 deletions

View File

@@ -17,8 +17,6 @@
*/
package org.jackhuang.hmcl.game;
import static org.jackhuang.hmcl.util.Logging.LOG;
import com.google.gson.JsonParseException;
import com.google.gson.annotations.SerializedName;
import org.jackhuang.hmcl.util.gson.JsonUtils;
@@ -35,19 +33,23 @@ import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.logging.Level;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import static org.jackhuang.hmcl.util.Lang.tryCast;
import static org.jackhuang.hmcl.util.Logging.LOG;
/**
* @author huangyuhui
*/
public final class GameVersion {
private static Optional<String> getVersionFromJson(Path versionJson) {
try {
MinecraftVersion version = JsonUtils.fromNonNullJson(FileUtils.readText(versionJson), MinecraftVersion.class);
return Optional.ofNullable(version.name);
Map<?, ?> version = JsonUtils.fromNonNullJson(FileUtils.readText(versionJson), Map.class);
return tryCast(version.get("name"), String.class);
} catch (IOException | JsonParseException e) {
LOG.log(Level.WARNING, "Failed to parse version.json", e);
return Optional.empty();

View File

@@ -278,13 +278,15 @@ public abstract class FetchTask<T> extends Task<T> {
if (DOWNLOAD_EXECUTOR == null) {
synchronized (Schedulers.class) {
if (DOWNLOAD_EXECUTOR == null) {
DOWNLOAD_EXECUTOR = new ThreadPoolExecutor(0, downloadExecutorConcurrency, 10, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(),
ThreadPoolExecutor executor = new ThreadPoolExecutor(downloadExecutorConcurrency, downloadExecutorConcurrency, 10, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(downloadExecutorConcurrency),
runnable -> {
Thread thread = Executors.defaultThreadFactory().newThread(runnable);
thread.setDaemon(true);
return thread;
});
executor.allowCoreThreadTimeOut(true);
DOWNLOAD_EXECUTOR = executor;
}
}
}