Getting OS memory size from java(从java获取操作系统内存大小)
问题描述
有没有什么方法可以从 java 中获取操作系统上总内存的大小?使用
Are there any way to get the size of the total memory on the operating system from java? Using
Runtime.getRuntime().maxMemory()
返回 JVM 允许的内存,而不是操作系统.有没有人有办法获得这个(从java代码)?
returns the allowed memory for the JVM, not of the operating system. Does anyone have a way to obtain this (from java code)?
推荐答案
com.sun.management.OperatingSystemMXBean bean =
(com.sun.management.OperatingSystemMXBean)
java.lang.management.ManagementFactory.getOperatingSystemMXBean();
long max = bean.getTotalPhysicalMemorySize();
返回 JVM 的可用 RAM 大小(受 32 位限制),而不是堆大小.
returns available RAM size for JVM (limited by 32bit), not the heap size.
这篇关于从java获取操作系统内存大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从java获取操作系统内存大小
基础教程推荐
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Struts2 URL 无法访问 2022-01-01
