|
43 | 43 | import java.util.concurrent.LinkedBlockingQueue; |
44 | 44 | import java.util.concurrent.ThreadPoolExecutor; |
45 | 45 | import java.util.concurrent.TimeUnit; |
| 46 | +import java.util.concurrent.atomic.AtomicLong; |
46 | 47 |
|
47 | 48 | /** |
48 | 49 | * [ WorldEdit action ] |
@@ -413,26 +414,31 @@ private void setupMemoryListener() { |
413 | 414 | final MemoryMXBean memBean = ManagementFactory.getMemoryMXBean(); |
414 | 415 | final NotificationEmitter ne = (NotificationEmitter) memBean; |
415 | 416 |
|
| 417 | + AtomicLong lastWarn = new AtomicLong(System.currentTimeMillis()); |
416 | 418 | ne.addNotificationListener((notification, handback) -> { |
417 | 419 | final long heapSize = Runtime.getRuntime().totalMemory(); |
418 | 420 | final long heapMaxSize = Runtime.getRuntime().maxMemory(); |
419 | 421 | if (heapSize < heapMaxSize) { |
420 | 422 | return; |
421 | 423 | } |
422 | | - LOGGER.warn("High memory usage detected, FAWE will attempt to slow operations to prevent a crash."); |
| 424 | + final long time = System.currentTimeMillis(); |
| 425 | + if (time > lastWarn.get() + TimeUnit.SECONDS.toMillis(30)) { |
| 426 | + lastWarn.set(time); |
| 427 | + LOGGER.warn("High memory usage detected, FAWE will attempt to slow operations to prevent a crash."); |
| 428 | + } |
423 | 429 | MemUtil.memoryLimitedTask(); |
424 | 430 | }, null, null); |
425 | 431 |
|
426 | 432 | final List<MemoryPoolMXBean> memPools = ManagementFactory.getMemoryPoolMXBeans(); |
427 | 433 | for (final MemoryPoolMXBean mp : memPools) { |
428 | | - if (mp.isUsageThresholdSupported()) { |
| 434 | + if (mp.isCollectionUsageThresholdSupported()) { |
429 | 435 | final MemoryUsage mu = mp.getUsage(); |
430 | 436 | final long max = mu.getMax(); |
431 | 437 | if (max < 0) { |
432 | 438 | continue; |
433 | 439 | } |
434 | 440 | final long alert = (max * Settings.settings().MAX_MEMORY_PERCENT) / 100; |
435 | | - mp.setUsageThreshold(alert); |
| 441 | + mp.setCollectionUsageThreshold(alert); |
436 | 442 | } |
437 | 443 | } |
438 | 444 | } catch (Throwable ignored) { |
|
0 commit comments