mirror of
https://github.com/Minestom/Minestom.git
synced 2024-09-28 14:37:31 +02:00
Experiment2: Move executor service inside method
This commit is contained in:
parent
bd5bb2e3d9
commit
dbc8cc54c1
@ -46,7 +46,6 @@ import java.util.function.Consumer;
|
||||
*/
|
||||
public class InstanceContainer extends Instance {
|
||||
|
||||
private ExecutorService parallelSavingThreadPool = new MinestomThread(MinecraftServer.THREAD_COUNT_PARALLEL_CHUNK_SAVING, MinecraftServer.THREAD_NAME_PARALLEL_CHUNK_SAVING);
|
||||
private static final String UUID_KEY = "uuid";
|
||||
private static final String DATA_KEY = "data";
|
||||
|
||||
@ -378,10 +377,12 @@ public class InstanceContainer extends Instance {
|
||||
public void saveChunksToStorageFolder(Runnable callback) {
|
||||
Check.notNull(getStorageFolder(), "You cannot save the instance if no StorageFolder has been defined");
|
||||
if(chunkLoader.supportsParallelSaving()) {
|
||||
ExecutorService parallelSavingThreadPool = new MinestomThread(MinecraftServer.THREAD_COUNT_PARALLEL_CHUNK_SAVING, MinecraftServer.THREAD_NAME_PARALLEL_CHUNK_SAVING, true);
|
||||
getChunks().forEach(c -> parallelSavingThreadPool.execute(() -> {
|
||||
saveChunkToStorageFolder(c, null);
|
||||
}));
|
||||
try {
|
||||
parallelSavingThreadPool.shutdown();
|
||||
parallelSavingThreadPool.awaitTermination(1L, java.util.concurrent.TimeUnit.DAYS);
|
||||
callback.run();
|
||||
} catch (InterruptedException e) {
|
||||
|
@ -14,14 +14,31 @@ public class MinestomThread extends ThreadPoolExecutor {
|
||||
|
||||
private static final List<MinestomThread> executors = new LinkedList<>();
|
||||
|
||||
/**
|
||||
* Creates a non-local thread pool executor
|
||||
* @param nThreads
|
||||
* @param name
|
||||
*/
|
||||
public MinestomThread(int nThreads, String name) {
|
||||
this(nThreads, name, false);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param nThreads
|
||||
* @param name
|
||||
* @param local set to true if this executor is only used inside a method and should *not* be kept in the internal list of executors
|
||||
*/
|
||||
public MinestomThread(int nThreads, String name, boolean local) {
|
||||
super(nThreads, nThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), r -> {
|
||||
Thread thread = new Thread(r);
|
||||
thread.setDaemon(true);
|
||||
thread.setName(thread.getName().replace("Thread", name));
|
||||
return thread;
|
||||
});
|
||||
executors.add(this);
|
||||
if(!local) {
|
||||
executors.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static void shutdownAll() {
|
||||
|
Loading…
Reference in New Issue
Block a user