如何在Java中找到物理内存大小? [英] How do I find the physical memory size in Java?

查看:439
本文介绍了如何在Java中找到物理内存大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个安装程序,它将调整产品的配置,以用于运行它的特定硬件。特别是,我想确定系统中安装了多少物理RAM,以便估算产品运行时分配给产品的内存量。

I'm writing an installer that will tune the configuration of the product for the particular hardware on which it will be run. In particular, I want to determine how much physical RAM is installed in the system so I can estimate how much memory to allocate to the product when it runs.

理想情况下,我我希望以独立于平台的纯Java方式实现这一点,因为安装程序需要在几个不同的平台上运行,但是如果不可能,则首选Windows解决方案,因为这是最常见的部署平台。

Ideally, I'd like to do this in a platform-independent, pure Java way, as the installer will need to run on several different platforms, but in case this isn't possible, solutions for Windows are preferred as that's the most common deployment platform.

在这种情况下,可以安全地假设产品将是盒子上运行的唯一/主要应用程序,因此我不必担心挤压其他人出。我不想过度分配,因为根据我们的经验,这可能会损害性能。

In this case, it's safe to assume that the product will be the only/main application running on the box, so I don't have to worry about squeezing anyone else out. I don't want to over-allocate as this, in our experience, can hurt performance.

推荐答案

对于Windows,你是'我需要访问WMI - 这将帮助您:访问Windows来自Java的管理工具(WMI)

For windows, you'll need to access WMI - this will get you going: Accessing Windows Management Instrumentation (WMI) from Java.

您将要使用WMI的这一部分:Win32_LogicalMemoryConfiguration。

You'll want to use this section of WMI: Win32_LogicalMemoryConfiguration.

可能有一种纯粹的java方式,但我不知道它。

There may be a pure java way of doing this, but I am unaware of it.

这篇关于如何在Java中找到物理内存大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆