本文整理了Java中java.lang.Runtime.maxMemory()
方法的一些代码示例,展示了Runtime.maxMemory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Runtime.maxMemory()
方法的具体详情如下:
包路径:java.lang.Runtime
类名称:Runtime
方法名:maxMemory
[英]Returns the maximum number of bytes the heap can expand to. See #totalMemory for the current number of bytes taken by the heap, and #freeMemory for the current number of those bytes actually used by live objects.
[中]返回堆可以扩展到的最大字节数。请参见#totalMemory了解堆当前占用的字节数,以及#freeMemory了解活动对象实际使用的字节数。
代码示例来源:origin: skylot/jadx
/**
* @return 20% of the maximum heap size limited to 512 MB (bytes)
*/
public static long calculateMinFreeMemory() {
Runtime runtime = Runtime.getRuntime();
long minFree = (long) (runtime.maxMemory() * 0.2);
return Math.min(minFree, 512 * 1024L * 1024L);
}
代码示例来源:origin: stackoverflow.com
Runtime rt = Runtime.getRuntime();
long maxMemory = rt.maxMemory();
Log.v("onCreate", "maxMemory:" + Long.toString(maxMemory));
代码示例来源: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: apache/incubator-druid
public long getMaxHeapSizeBytes()
{
return Runtime.getRuntime().maxMemory();
}
代码示例来源: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: neo4j/neo4j
private double determineGoodBufferSize( double atLeast )
{
double heapHint = Runtime.getRuntime().maxMemory() / (1024 * 1024 * 14);
double result = Math.max( atLeast, heapHint );
return Math.min( result, 700 );
}
代码示例来源:origin: stanfordnlp/CoreNLP
public int getMaxAvailableMemory(boolean accurate) {
if (accurate) {
System.gc();
}
return (int) ((r.maxMemory() - r.totalMemory() + r.freeMemory()) / 1024);
}
代码示例来源:origin: redisson/redisson
/**
* Returns the amount of available memory (free memory plus never allocated memory).
*/
public static long availableMemory() {
return Runtime.getRuntime().freeMemory() + (Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory());
}
代码示例来源:origin: redisson/redisson
/**
* Returns the amount of available memory in percents.
*/
public static float availableMemoryPercent() {
return availableMemory() * 100.0f / Runtime.getRuntime().maxMemory();
}
代码示例来源:origin: apache/flink
private static void verifyJvmOptions() {
long heap = Runtime.getRuntime().maxMemory() >> 20;
Assert.assertTrue("Insufficient java heap space " + heap + "mb - set JVM option: -Xmx" + MINIMUM_HEAP_SIZE_MB
+ "m", heap > MINIMUM_HEAP_SIZE_MB - 50);
}
代码示例来源: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: prestodb/presto
@Inject
public LocalMemoryManager(NodeMemoryConfig config, ReservedSystemMemoryConfig systemMemoryConfig)
{
requireNonNull(config, "config is null");
long availableMemory = Runtime.getRuntime().maxMemory();
if (config.isLegacySystemPoolEnabled()) {
configureLegacyMemoryPools(config, systemMemoryConfig, availableMemory);
}
else {
configureMemoryPools(config, availableMemory);
}
}
代码示例来源:origin: neo4j/neo4j
private static String memoryStats()
{
Runtime runtime = Runtime.getRuntime();
return format( "Memory[used:%s, free:%s, total:%s, max:%s]",
Format.bytes( runtime.totalMemory() - runtime.freeMemory() ),
Format.bytes( runtime.freeMemory() ),
Format.bytes( runtime.totalMemory() ),
Format.bytes( runtime.maxMemory() ) );
}
代码示例来源: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);
}
代码示例来源:origin: greenrobot/EventBus
@Test
public void testUnregisterNotLeaking() {
int heapMBytes = (int) (Runtime.getRuntime().maxMemory() / (1024L * 1024L));
for (int i = 0; i < heapMBytes * 2; i++) {
@SuppressWarnings("unused")
EventBusBasicTest subscriber = new EventBusBasicTest() {
byte[] expensiveObject = new byte[1024 * 1024];
};
eventBus.register(subscriber);
eventBus.unregister(subscriber);
log("Iteration " + i + " / max heap: " + heapMBytes);
}
}
代码示例来源:origin: apache/flink
private static void verifyJvmOptions() {
final long heap = Runtime.getRuntime().maxMemory() >> 20;
Assert.assertTrue("Insufficient java heap space " + heap + "mb - set JVM option: -Xmx" + MINIMUM_HEAP_SIZE_MB
+ "m", heap > MINIMUM_HEAP_SIZE_MB - 50);
}
代码示例来源:origin: neo4j/neo4j
public void dumpConfiguration()
{
checkPageSize( config );
String pageCacheMemory = config.get( pagecache_memory );
long totalPhysicalMemory = OsBeanUtil.getTotalPhysicalMemory();
String totalPhysicalMemMb = (totalPhysicalMemory == OsBeanUtil.VALUE_UNAVAILABLE)
? "?" : "" + ByteUnit.Byte.toMebiBytes( totalPhysicalMemory );
long maxVmUsageMb = ByteUnit.Byte.toMebiBytes( Runtime.getRuntime().maxMemory() );
String msg = "Physical mem: " + totalPhysicalMemMb + " MiB," +
" Heap size: " + maxVmUsageMb + " MiB," +
" Page cache: " + pageCacheMemory + ".";
log.info( msg );
}
代码示例来源:origin: skylot/jadx
public HeapUsageBar() {
this.textFormat = NLS.str("heapUsage.text");
setBorderPainted(false);
setStringPainted(true);
setValue(10);
int maxKB = (int) (runtime.maxMemory() / 1024);
setMaximum(maxKB);
maxGB = maxKB / TWO_TO_20;
update();
timer = new Timer(2000, this);
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
Runtime.getRuntime().gc();
update();
if (LOG.isDebugEnabled()) {
LOG.debug("Memory used: {}", Utils.memoryInfo());
}
}
});
}
代码示例来源:origin: greenrobot/EventBus
@Test
public void testUnregisterNotLeaking() {
int heapMBytes = (int) (Runtime.getRuntime().maxMemory() / (1024L * 1024L));
for (int i = 0; i < heapMBytes * 2; i++) {
@SuppressWarnings("unused")
EventBusBasicTest subscriber = new EventBusBasicTest() {
byte[] expensiveObject = new byte[1024 * 1024];
};
eventBus.register(subscriber);
eventBus.unregister(subscriber);
log("Iteration " + i + " / max heap: " + heapMBytes);
}
}
内容来源于网络,如有侵权,请联系作者删除!