简体   繁体   English

我应该使用 32 位还是 64 位 JDK?

[英]Should I use 32-bit or 64-bit JDK?

Years ago, I tried 64-bit JDK but it was really buggy.多年前,我尝试过 64 位 JDK,但它确实有问题。

How stable would you say it is now?你说它现在有多稳定? Would you recommend it?你会推荐它吗? Should I install 64-bit JDK + eclipse or stick to 32-bit?我应该安装 64 位 JDK + eclipse 还是坚持使用 32 位? Also, are there any advantages of 64-bit over 32-bit other than bypassing the 4 GB memory limit?另外,除了绕过 4 GB 内存限制之外,64 位比 32 位还有什么优势吗?

Only begin to bother with that if you want to build an application that will use a lot of memory (namely, a heap larger than 2GB).如果您想构建一个将使用大量内存(即大于 2GB 的堆)的应用程序,则只有开始为此烦恼。

Allow me to quote Red Hat:请允许我引用 Red Hat:

The real advantage of the 64-bit JVM is that heap sizes much larger than 2GB can be used. 64 位 JVM 的真正优势在于可以使用远大于 2GB 的堆大小。 Large page memory with the 64-bit JVM give further optimizations.带有 64 位 JVM 的大页面内存提供了进一步的优化。 The following graph shows the results running from 4GB heap sizes, in two gigabyte increments, up to 20GB heap.下图显示了从 4GB 堆大小(以 2 GB 为增量)运行到 20GB 堆的结果。

That, in a pretty graph:那,在一个漂亮的图表中:

32 位与 64 位 JVM 的性能对比

See, no big difference.看,没有太大区别。

See more (more graphs, yay!) in: Java Virtual Machine Tuning查看更多(更多图表,是的!): Java 虚拟机调优

I think the answer can be found pretty simple.我认为答案很简单。

Answer the question: "Do I need more than 4GB of RAM?".回答问题:“我需要超过 4GB 的内存吗?”。

A 64 bit JVM is as stable as a 32 bit JVM. 64 位 JVM 与 32 位 JVM 一样稳定。 There are no differences.没有区别。 In fact a Java Application running in a 64 bit JVM will consume more RAM compared to a 32 bit JVM.事实上,与 32 位 JVM 相比,在 64 位 JVM 中运行的 Java 应用程序将消耗更多 RAM。 All internal datastructures will need more RAM.所有内部数据结构都需要更多 RAM。

My eclipse is running in a 64bit JVM.我的日食在 64 位 JVM 中运行。

Are you going to deploy to a 32 or a 64 bit environment?您打算部署到 32 位还是 64 位环境? If you're affinitized to an environment in production then your development environment should use the same environment type.如果您与生产环境相关联,那么您的开发环境应该使用相同的环境类型。

If you're platform agnostic, go with x64 and don't even think about it.如果您与平台无关,请使用 x64,甚至不要考虑它。 The platform is mature and stable.平台成熟稳定。 It gives you tremendous room to scale up as you can just add memory and make your heaps bigger.它为您提供了巨大的扩展空间,因为您只需添加内存并使堆更大。

Nobody wants to tell a CEO, "Sorry, we chose x86 and can't scale up like we hoped. It's a month long project project to retest and replatform everything for x64."没有人愿意对 CEO 说:“抱歉,我们选择了 x86,但无法像我们希望的那样扩展。这是一个为期一个月的项目,为 x64 重新测试和重新构建所有平台。”

The only differences between 32-bit and 64-bit builds of any program are the sizes of machine words, the amount of addressable memory, and the Operating System ABI in use.任何程序的 32 位和 64 位版本之间的唯一区别是机器字的大小、可寻址内存的数量和使用的操作系统 ABI。 With Java, the language specification means that the differences in machine word size and OS ABI should not matter at all unless you're using native code as well.对于 Java,语言规范意味着机器字大小和操作系统 ABI 的差异根本无关紧要,除非您也使用本机代码。 (Native code must be built to be the same as the word-size of the JVM that will load it; you can't mix 32-bit and 64-bit builds in the same process without very exotic coding indeed, and you shouldn't be doing that with Java about.) (本机代码必须构建为与加载它的 JVM 的字大小相同;如果没有非常奇特的编码,您不能在同一进程中混合 32 位和 64 位构建,并且您不应该不要用 Java 来做这件事。)

The 64-bitter uses 64-bit pointers. 64 位使用 64 位指针。 If you have 4GB+ RAM, and are running Java programs that keep 4GB+ of data structures in memory, the 64-bitter will accommodate that.如果您有 4GB+ 的 RAM,并且正在运行在内存中保留 4GB+ 数据结构的 Java 程序,那么 64 位将容纳它。 The big fat pointers can point to any byte in a 4GB+ memory space.大胖指针可以指向 4GB+ 内存空间中的任何字节。

But if your programs use less memory, and you run the 64-bit JVM, pointers in will still occupy 64 bits (8 bytes) each.但是如果您的程序使用较少的内存,并且您运行 64 位 JVM,则每个指针仍将占用 64 位(8 字节)。 This will cause data structures to be bigger, which will eat up memory unnecessarily.这将导致数据结构更大,这将不必要地消耗内存。

I just compiled a MQTT client in both the 32-bit JDK (jdk-8u281-windows-i586) and the 64-bit JDK (jdk-8u281-windows-x64).我刚刚在 32 位 JDK (jdk-8u281-windows-i586) 和 64 位 JDK (jdk-8u281-windows-x64) 中编译了一个 MQTT 客户端。 The class files produced had matching MD5 checksums.生成的类文件具有匹配的 MD5 校验和。

FYI, it's perfectly safe to have multiple JDKs on your system.仅供参考,在您的系统上安装多个 JDK 是完全安全的。 But if the version you use is important, you should be comfortable with setting your system path and JAVA_HOME to ensure the correct version is used.但是,如果您使用的版本很重要,您应该对设置系统路径和 JAVA_HOME 以确保使用正确的版本感到满意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM