Multi IO threads w/ fixes default config value
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -14,13 +17,27 @@ public class FileIOThread implements Runnable {
|
||||
private volatile long d;
|
||||
private volatile long e;
|
||||
private volatile boolean f;
|
||||
// Akarin start
|
||||
private final java.util.concurrent.ExecutorService executor = java.util.concurrent.Executors.newFixedThreadPool(io.akarin.server.core.AkarinGlobalConfig.fileIOThreads, new com.google.common.util.concurrent.ThreadFactoryBuilder().setUncaughtExceptionHandler(new ThreadNamedUncaughtExceptionHandler(FileIOThread.a)).setNameFormat("Akarin File IO Thread - %1$d").setPriority(1).build());
|
||||
|
||||
@lombok.SneakyThrows
|
||||
private void writeChunk(IAsyncChunkSaver iasyncchunksaver) {
|
||||
if (!iasyncchunksaver.a() /* writeNextIO */) { // returns whether the writing was unsuccessful
|
||||
if (com.destroystokyo.paper.PaperConfig.enableFileIOThreadSleep) { // Paper
|
||||
Thread.sleep(this.f ? 0L : 2L); // Paper
|
||||
}
|
||||
} else {
|
||||
writeChunk(iasyncchunksaver);
|
||||
}
|
||||
}
|
||||
// Akarin end
|
||||
|
||||
private FileIOThread() {
|
||||
Thread thread = new Thread(this, "File IO Thread");
|
||||
|
||||
thread.setUncaughtExceptionHandler(new ThreadNamedUncaughtExceptionHandler(FileIOThread.a));
|
||||
thread.setPriority(1);
|
||||
thread.start();
|
||||
//thread.start(); // Akarin
|
||||
}
|
||||
|
||||
public static FileIOThread a() {
|
||||
@@ -66,10 +83,13 @@ public class FileIOThread implements Runnable {
|
||||
}
|
||||
|
||||
public void a(IAsyncChunkSaver iasyncchunksaver) {
|
||||
if (!this.c.contains(iasyncchunksaver)) {
|
||||
++this.d;
|
||||
this.c.add(iasyncchunksaver);
|
||||
}
|
||||
// Akarin start
|
||||
//if (!this.c.contains(iasyncchunksaver)) {
|
||||
// ++this.d;
|
||||
// this.c.add(iasyncchunksaver);
|
||||
//}
|
||||
executor.execute(() -> writeChunk(iasyncchunksaver));
|
||||
// Akarin end
|
||||
}
|
||||
|
||||
public void b() throws InterruptedException {
|
||||
@@ -78,6 +98,8 @@ public class FileIOThread implements Runnable {
|
||||
while(!this.getThreadedIOQueue().isEmpty()) { // Paper - check actual list size
|
||||
Thread.sleep(10L);
|
||||
}
|
||||
executor.shutdown(); // Akarin
|
||||
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); // Akarin
|
||||
|
||||
this.f = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user