java.lang.Runtime.totalMemory()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(208)

本文整理了Java中java.lang.Runtime.totalMemory()方法的一些代码示例,展示了Runtime.totalMemory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Runtime.totalMemory()方法的具体详情如下:
包路径:java.lang.Runtime
类名称:Runtime
方法名:totalMemory

Runtime.totalMemory介绍

[英]Returns the number of bytes taken by the heap at its current size. The heap may expand or contract over time, as the number of live objects increases or decreases. See #maxMemory for the maximum heap size, and #freeMemory for an idea of how much the heap could currently contract.
[中]返回堆在其当前大小下占用的字节数。随着活动对象数量的增加或减少,堆可能会随着时间的推移而扩展或收缩。请参阅#maxMemory了解最大堆大小,以及#freemory了解堆当前可收缩的大小。

代码示例

代码示例来源:origin: skylot/jadx

public static boolean isFreeMemoryAvailable() {
  Runtime runtime = Runtime.getRuntime();
  long maxMemory = runtime.maxMemory();
  long totalFree = runtime.freeMemory() + (maxMemory - runtime.totalMemory());
  return totalFree > MIN_FREE_MEMORY;
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getJavaHeap () {
  return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getJavaHeap () {
  return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getJavaHeap () {
  return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getJavaHeap () {
  return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getJavaHeap() {
  return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getJavaHeap () {
  return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getJavaHeap () {
  return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getJavaHeap () {
  return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getJavaHeap () {
  return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getJavaHeap () {
  return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getJavaHeap () {
  return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getJavaHeap () {
  return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}

代码示例来源:origin: libgdx/libgdx

@Override
public long getJavaHeap () {
  return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public Status check() {
  Runtime runtime = Runtime.getRuntime();
  long freeMemory = runtime.freeMemory();
  long totalMemory = runtime.totalMemory();
  long maxMemory = runtime.maxMemory();
  boolean ok = (maxMemory - (totalMemory - freeMemory) > 2048); // Alarm when spare memory < 2M
  String msg = "max:" + (maxMemory / 1024 / 1024) + "M,total:"
      + (totalMemory / 1024 / 1024) + "M,used:" + ((totalMemory / 1024 / 1024) - (freeMemory / 1024 / 1024)) + "M,free:" + (freeMemory / 1024 / 1024) + "M";
  return new Status(ok ? Status.Level.OK : Status.Level.WARN, msg);
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public Status check() {
  Runtime runtime = Runtime.getRuntime();
  long freeMemory = runtime.freeMemory();
  long totalMemory = runtime.totalMemory();
  long maxMemory = runtime.maxMemory();
  boolean ok = (maxMemory - (totalMemory - freeMemory) > 2048); // Alarm when spare memory < 2M
  String msg = "max:" + (maxMemory / 1024 / 1024) + "M,total:"
      + (totalMemory / 1024 / 1024) + "M,used:" + ((totalMemory / 1024 / 1024) - (freeMemory / 1024 / 1024)) + "M,free:" + (freeMemory / 1024 / 1024) + "M";
  return new Status(ok ? Status.Level.OK : Status.Level.WARN, msg);
}

代码示例来源:origin: skylot/jadx

public void update() {
  long used = runtime.totalMemory() - runtime.freeMemory();
  int usedKB = (int) (used / 1024);
  setValue(usedKB);
  setString(String.format(textFormat, (usedKB / TWO_TO_20), maxGB));
  if ((used + Utils.MIN_FREE_MEMORY) > runtime.maxMemory()) {
    setForeground(RED);
  } else {
    setForeground(GREEN);
  }
}

代码示例来源:origin: ReactiveX/RxJava

@Override
  public void run() {
    i++;
    if (i % 100000 == 0) {
      System.out.println(i + "  Total Memory: " + Runtime.getRuntime().totalMemory() + "  Free: " + Runtime.getRuntime().freeMemory());
    }
    if (i < 1000000L) {
      inner.schedule(this);
    } else {
      latch.countDown();
    }
  }
});

代码示例来源:origin: ReactiveX/RxJava

@Override
  public void run() {
    i++;
    if (i % 100000 == 0) {
      System.out.println(i + "  Total Memory: " + Runtime.getRuntime().totalMemory() + "  Free: " + Runtime.getRuntime().freeMemory());
    }
    if (i < 1000000L) {
      inner.schedule(this);
    } else {
      latch.countDown();
    }
  }
});

代码示例来源:origin: skylot/jadx

public static String memoryInfo() {
  Runtime runtime = Runtime.getRuntime();
  long maxMemory = runtime.maxMemory();
  long allocatedMemory = runtime.totalMemory();
  long freeMemory = runtime.freeMemory();
  return "heap: " + format(allocatedMemory - freeMemory) +
      ", allocated: " + format(allocatedMemory) +
      ", free: " + format(freeMemory) +
      ", total free: " + format(freeMemory + maxMemory - allocatedMemory) +
      ", max: " + format(maxMemory);
}

相关文章