Fix java.lang.IllegalArgumentException crash issue.

This bug will cause server crash, and these lines will shown in crash-report.

```
Description: Exception in server tick loop

java.lang.ExceptionInInitializerError
	at net.minecraft.server.v1_13_R2.PlayerList.sendAll(PlayerList.java:1099)
	at net.minecraft.server.v1_13_R2.World$2.a(World.java:226)
	at net.minecraft.server.v1_13_R2.WorldBorder.setCenter(WorldBorder.java:94)
	at net.minecraft.server.v1_13_R2.WorldServer.i_(WorldServer.java:112)
	at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:367)
	at net.minecraft.server.v1_13_R2.DedicatedServer.init(DedicatedServer.java:316)
	at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:789)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalArgumentException
	at java.util.concurrent.ThreadPoolExecutor.<init>(ThreadPoolExecutor.java:1314)
	at java.util.concurrent.ThreadPoolExecutor.<init>(ThreadPoolExecutor.java:1237)
	at java.util.concurrent.Executors.newFixedThreadPool(Executors.java:151)
	at io.akarin.server.core.AkarinAsyncExecutor.<clinit>(AkarinAsyncExecutor.java:12)
	... 8 more

```
This commit is contained in:
Ghost_chu
2019-03-28 21:35:47 +08:00
parent 94ba1bb082
commit 77ffdd0475

View File

@@ -9,8 +9,17 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder;
public class AkarinAsyncExecutor {
private static final ExecutorService singleExecutor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("Akarin Single Async Executor Thread - %1$d").build());
private static final ExecutorService asyncExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() / 4, new ThreadFactoryBuilder().setNameFormat("Akarin Async Executor Thread - %1$d").build());
private static final ExecutorService asyncExecutor = Executors.newFixedThreadPool(getnThreads(), new ThreadFactoryBuilder().setNameFormat("Akarin Async Executor Thread - %1$d").build());
private static int getnThreads(){
int processors = Runtime.getRuntime().availableProcessors();
if(processors > 2){
return processors;
}else {
return 2;
}
}
/**
* Posts a task to be executed asynchronously in a single thread
* @param run