如何判断我是在 64 位 JVM 还是 32 位 JVM 中运行(从程序中)? [英] How can I tell if I'm running in 64-bit JVM or 32-bit JVM (from within a program)?

查看:40
本文介绍了如何判断我是在 64 位 JVM 还是 32 位 JVM 中运行(从程序中)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何判断我的应用程序运行所在的 JVM 是 32 位还是 64 位?具体来说,我可以使用哪些函数或属性来检测程序中的这一点?

How can I tell if the JVM in which my application runs is 32 bit or 64-bit? Specifically, what functions or properties I can used to detect this within the program?

推荐答案

您检索了 系统属性 标记此 JVM 的位数:

You retrieve the system property that marks the bitness of this JVM with:

System.getProperty("sun.arch.data.model");

可能的结果是:

  • 32" – 32 位 JVM
  • 64" – 64 位 JVM
  • unknown" – 未知的 JVM
  • "32" – 32-bit JVM
  • "64" – 64-bit JVM
  • "unknown" – Unknown JVM

HotSpot 常见问题解答中所述:

在编写Java代码时,如何区分32位和64位操作?

没有允许您区分 32 位和 64 位操作的公共 API.将 64 位视为一次编写,随处运行的传统平台.但是,如果您想编写特定于平台的代码(让您感到羞耻),则系统属性 sun.arch.data.model 具有值32"、64"或未知".

There's no public API that allows you to distinguish between 32 and 64-bit operation. Think of 64-bit as just another platform in the write once, run anywhere tradition. However, if you'd like to write code which is platform specific (shame on you), the system property sun.arch.data.model has the value "32", "64", or "unknown".

如果您的 Java 代码依赖于本机库,并且您需要确定是在启动时加载 32 位还是 64 位版本的库,则可能需要这样做.

An example where this could be necessary is if your Java code depends on native libraries, and you need to determine whether to load the 32- or 64-bit version of the libraries on startup.

这篇关于如何判断我是在 64 位 JVM 还是 32 位 JVM 中运行(从程序中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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