diff --git a/core/src/main/java/com/volmit/iris/core/service/IrisEngineSVC.java b/core/src/main/java/com/volmit/iris/core/service/IrisEngineSVC.java index a1b2bcf5d..c14068874 100644 --- a/core/src/main/java/com/volmit/iris/core/service/IrisEngineSVC.java +++ b/core/src/main/java/com/volmit/iris/core/service/IrisEngineSVC.java @@ -100,7 +100,7 @@ public class IrisEngineSVC implements IrisService { Engine engine = supplier.get(); if (engine != null) { long unloadStart = System.currentTimeMillis(); - int count = engine.getMantle().unloadTectonicPlate(); + int count = engine.getMantle().unloadTectonicPlate(tectonicLimit.get() / lastUse.size()); if (count > 0) { Iris.debug(C.GOLD + "Unloaded " + C.YELLOW + count + " TectonicPlates in " + C.RED + Form.duration(System.currentTimeMillis() - unloadStart, 2)); } diff --git a/core/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java b/core/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java index fe17b0655..c8326ffd0 100644 --- a/core/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java +++ b/core/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java @@ -178,8 +178,8 @@ public interface EngineMantle extends IObjectPlacer { default void trim(int limit) { getMantle().trim(TimeUnit.SECONDS.toMillis(IrisSettings.get().getPerformance().getMantleKeepAlive()), limit); } - default int unloadTectonicPlate(){ - return getMantle().unloadTectonicPlate(); + default int unloadTectonicPlate(int tectonicLimit){ + return getMantle().unloadTectonicPlate(tectonicLimit); } default MultiBurst burst() { diff --git a/core/src/main/java/com/volmit/iris/util/mantle/Mantle.java b/core/src/main/java/com/volmit/iris/util/mantle/Mantle.java index 2c4bad8c7..8136fe890 100644 --- a/core/src/main/java/com/volmit/iris/util/mantle/Mantle.java +++ b/core/src/main/java/com/volmit/iris/util/mantle/Mantle.java @@ -444,15 +444,15 @@ public class Mantle { } } - public int unloadTectonicPlate() { + public int unloadTectonicPlate(int tectonicLimit) { // todo: Make it advanced with bursts etc AtomicInteger i = new AtomicInteger(); unloadLock.lock(); try { - List> futures = new ArrayList<>(); - ExecutorService service = Executors.newFixedThreadPool(dynamicThreads.get()); + BurstExecutor burst = MultiBurst.burst.burst(toUnload.size()); + burst.setMulticore(toUnload.size() > tectonicLimit); for (long id : new ArrayList<>(toUnload)) { - futures.add(service.submit(() -> + burst.queue(() -> hyperLock.withLong(id, () -> { TectonicPlate m = loadedRegions.get(id); if (m != null) { @@ -467,16 +467,10 @@ public class Mantle { e.printStackTrace(); } } - }))); + })); } - try { - while (!futures.isEmpty()) { - futures.remove(0).get(); - futures.removeIf(Future::isDone); - } - service.shutdown(); - } catch (InterruptedException ignored) {} + burst.complete(); } catch (Exception e) { e.printStackTrace(); } finally {