fix: RejectedExecutionException
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
package org.jackhuang.hmcl.game;
|
||||
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import org.jackhuang.hmcl.util.gson.JsonUtils;
|
||||
import org.jackhuang.hmcl.util.io.CompressingUtils;
|
||||
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||
@@ -114,24 +113,4 @@ public final class GameVersion {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class MinecraftVersion {
|
||||
public String name;
|
||||
|
||||
@SerializedName("release_target")
|
||||
public String releaseTarget;
|
||||
|
||||
public String id;
|
||||
|
||||
public boolean stable;
|
||||
|
||||
@SerializedName("world_version")
|
||||
public int worldVersion;
|
||||
|
||||
@SerializedName("protocol_version")
|
||||
public int protocolVersion;
|
||||
|
||||
@SerializedName("pack_version")
|
||||
public int packVersion;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,8 @@ import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static org.jackhuang.hmcl.util.Lang.threadPool;
|
||||
|
||||
public abstract class FetchTask<T> extends Task<T> {
|
||||
protected final List<URL> urls;
|
||||
protected final int retry;
|
||||
@@ -278,15 +280,7 @@ public abstract class FetchTask<T> extends Task<T> {
|
||||
if (DOWNLOAD_EXECUTOR == null) {
|
||||
synchronized (Schedulers.class) {
|
||||
if (DOWNLOAD_EXECUTOR == null) {
|
||||
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;
|
||||
DOWNLOAD_EXECUTOR = threadPool("Download", true, downloadExecutorConcurrency, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ import org.jackhuang.hmcl.util.Logging;
|
||||
import javax.swing.*;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import static org.jackhuang.hmcl.util.Lang.threadPool;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author huangyuhui
|
||||
@@ -47,13 +49,7 @@ public final class Schedulers {
|
||||
if (IO_EXECUTOR == null) {
|
||||
synchronized (Schedulers.class) {
|
||||
if (IO_EXECUTOR == null) {
|
||||
IO_EXECUTOR = new ThreadPoolExecutor(0, 4, 10, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<>(),
|
||||
runnable -> {
|
||||
Thread thread = Executors.defaultThreadFactory().newThread(runnable);
|
||||
thread.setDaemon(true);
|
||||
return thread;
|
||||
});
|
||||
IO_EXECUTOR = threadPool("IO", true, 4, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,12 +202,12 @@ public final class Lang {
|
||||
|
||||
public static ThreadPoolExecutor threadPool(String name, boolean daemon, int threads, long timeout, TimeUnit timeunit) {
|
||||
AtomicInteger counter = new AtomicInteger(1);
|
||||
ThreadPoolExecutor pool = new ThreadPoolExecutor(0, threads, timeout, timeunit, new LinkedBlockingQueue<>(), r -> {
|
||||
ThreadPoolExecutor pool = new ThreadPoolExecutor(threads, threads, timeout, timeunit, new LinkedBlockingQueue<>(), r -> {
|
||||
Thread t = new Thread(r, name + "-" + counter.getAndIncrement());
|
||||
t.setDaemon(daemon);
|
||||
return t;
|
||||
});
|
||||
pool.allowsCoreThreadTimeOut();
|
||||
pool.allowCoreThreadTimeOut(true);
|
||||
return pool;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user