diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/DataSourcePool.java b/core/src/main/java/com/seibel/distanthorizons/core/file/DataSourcePool.java index 82ffb1fd9..7af2fc17e 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/DataSourcePool.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/DataSourcePool.java @@ -2,6 +2,7 @@ package com.seibel.distanthorizons.core.file; import com.seibel.distanthorizons.core.level.IDhLevel; import com.seibel.distanthorizons.core.pos.DhSectionPos; +import com.seibel.distanthorizons.core.util.ThreadUtil; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -16,6 +17,13 @@ import java.util.function.Function; */ public class DataSourcePool, TDhLevel extends IDhLevel> { + /** + * James tested with a static 25 on a 8 core 16 processor machine and didn't have any issues. + * In most cases the number of pooled sources won't probably even get close to the number of processors, + * but just in case the user has a overkill CPU (or config) this should hopefully prevent thrashing. + */ + private static final int MAX_POOLED_SOURCES = Runtime.getRuntime().availableProcessors() * 2; + private final ArrayList pooledDataSources = new ArrayList<>(); private final ReentrantLock poolLock = new ReentrantLock(); @@ -90,7 +98,7 @@ public class DataSourcePool, TDhLevel { return; } - else if (this.pooledDataSources.size() > 25) + else if (this.pooledDataSources.size() > MAX_POOLED_SOURCES) { return; }