You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by xi...@apache.org on 2022/06/07 07:31:25 UTC

[incubator-shenyu] branch master updated: [type:refactor] make maxAvailable easier to understand (#3493)

This is an automated email from the ASF dual-hosted git repository.

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 73a942ba8 [type:refactor] make maxAvailable easier to understand (#3493)
73a942ba8 is described below

commit 73a942ba866f574fff9ce9eb0d3b1846639f7997
Author: dragon-zhang <ha...@webuy.ai>
AuthorDate: Tue Jun 7 15:31:19 2022 +0800

    [type:refactor] make maxAvailable easier to understand (#3493)
---
 .../shenyu/common/concurrent/MemoryLimitCalculator.java      | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/MemoryLimitCalculator.java b/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/MemoryLimitCalculator.java
index d28d130d8..0930df511 100644
--- a/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/MemoryLimitCalculator.java
+++ b/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/MemoryLimitCalculator.java
@@ -17,24 +17,19 @@
 
 package org.apache.shenyu.common.concurrent;
 
-import java.lang.management.ManagementFactory;
-import java.lang.management.MemoryMXBean;
-import java.lang.management.MemoryUsage;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 
 /**
- * {@link javax.management.MXBean} technology is used to calculate the memory
- * limit by using the percentage of the current maximum available memory,
+ * {@link java.lang.Runtime#freeMemory()} technology is used to calculate the
+ * memory limit by using the percentage of the current maximum available memory,
  * which can be used with {@link org.apache.shenyu.common.concurrent.MemoryLimiter}.
  *
  * @see org.apache.shenyu.common.concurrent.MemoryLimiter
  */
 public class MemoryLimitCalculator {
 
-    private static final MemoryMXBean MX_BEAN = ManagementFactory.getMemoryMXBean();
-
     private static volatile long maxAvailable;
 
     private static final ScheduledExecutorService SCHEDULER = Executors.newSingleThreadScheduledExecutor();
@@ -48,8 +43,7 @@ public class MemoryLimitCalculator {
     }
 
     private static void refresh() {
-        final MemoryUsage usage = MX_BEAN.getHeapMemoryUsage();
-        maxAvailable = usage.getCommitted();
+        maxAvailable = Runtime.getRuntime().freeMemory();
     }
 
     /**