我怎样才能知道,如果我在64位JVM还是32位JVM(在程序中)运行? [英] How can I tell if I'm running in 64-bit JVM or 32-bit JVM (from within a program)?

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

问题描述

我怎样才能知道,如果JVM我的应用程序中是32位还是64位运行?具体而言,有什么功能或preference做我接触到程序中检测到这一点?

How can I tell if the JVM my application runs in is 32 bit or 64-bit? Specifically, what function or preference do I access to detect this within the program?

推荐答案

Sun公司Java系统属性来确定JVM的位数:32或64:

Sun has a Java System property to determine the bitness of the JVM: 32 or 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的程序。

to determine if its 32/64 from the program.

在<一个href="http://www.oracle.com/technetwork/java/hotspotfaq-138619.html#64bit_detection">sun.docs:

在编写Java code,我该怎么办   32至64位的区别   操作?

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

有没有公共API,可以让你   32至64位的区别   操作。想想64位为刚   在写另一个平台一次,   在任何地方运行的传统。然而,如果   你想写code这是   平台特定的(可耻的是你)时,   系统属性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  code是依赖于本地库  和你的code需要确定哪些  版本(32位或64位),在启动时加载。

The only good reason is if your java code is dependent upon native libraries and your code needs to determine which version (32 or 64bit) to load on startup.

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

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