我怎么知道我在64位jvm或32位jvm(从程序中)运行?


如何判断我的应用程序运行的JVM是32位还是64位?具体来说,我可以在程序中检测到什么功能或偏好?

Sun有一个Java系统属性来确定JVM的位数:32或64:

sun.arch.data.model=32 // 32 bit JVM
sun.arch.data.model=64 // 64 bit JVM

您可以使用

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

确定它是否是32/64的程序。

Sun
HotSpot常见问题解答

When writing Java code, how do I distinguish between 32 and 64-bit
operation?

>

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位)在启动时加载。

你可以试试命令行:

java -d64 -version

如果它不是64位版本,则会显示一条消息:

This Java instance does not support a 64-bit JVM. Please install the desired
version.

请参阅JVM的帮助选项以获取更多信息java -help

未经作者同意,本文严禁转载,违者必究!