diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/Fawe.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/Fawe.java index 57a61d1f0e..37c6796b5a 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/Fawe.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/Fawe.java @@ -43,6 +43,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; /** * [ WorldEdit action ] @@ -413,26 +414,31 @@ private void setupMemoryListener() { final MemoryMXBean memBean = ManagementFactory.getMemoryMXBean(); final NotificationEmitter ne = (NotificationEmitter) memBean; + AtomicLong lastWarn = new AtomicLong(System.currentTimeMillis()); ne.addNotificationListener((notification, handback) -> { final long heapSize = Runtime.getRuntime().totalMemory(); final long heapMaxSize = Runtime.getRuntime().maxMemory(); if (heapSize < heapMaxSize) { return; } - LOGGER.warn("High memory usage detected, FAWE will attempt to slow operations to prevent a crash."); + final long time = System.currentTimeMillis(); + if (time > lastWarn.get() + TimeUnit.SECONDS.toMillis(30)) { + lastWarn.set(time); + LOGGER.warn("High memory usage detected, FAWE will attempt to slow operations to prevent a crash."); + } MemUtil.memoryLimitedTask(); }, null, null); final List memPools = ManagementFactory.getMemoryPoolMXBeans(); for (final MemoryPoolMXBean mp : memPools) { - if (mp.isUsageThresholdSupported()) { + if (mp.isCollectionUsageThresholdSupported()) { final MemoryUsage mu = mp.getUsage(); final long max = mu.getMax(); if (max < 0) { continue; } final long alert = (max * Settings.settings().MAX_MEMORY_PERCENT) / 100; - mp.setUsageThreshold(alert); + mp.setCollectionUsageThreshold(alert); } } } catch (Throwable ignored) {